Javascript, HTML, CSS Code
Copy
<html>
<head>
<script type="text/javascript"> window.addEventListener('error', function(event) { var message = JSON.parse(JSON.stringify(event.message)); var source = event.filename; var lineno = event.lineno; var colno = event.colno; var error = event.error; window.parent.postMessage({ type: 'iframeError', details: { message: message, source: source, lineno: lineno, colno: colno, error: error ? error.stack : '' } }, '*'); }); window.addEventListener('unhandledrejection', function(event) { window.parent.postMessage({ type: 'iframePromiseRejection', details: { reason: event.reason } }, '*'); }); </script>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>XBox Controller App</title>
<meta name="description" content="A fun, responsive, mobile-friendly app mimicking an XBox controller layout with interactive joysticks and buttons.">
<meta name="keywords" content="xbox, controller, mobile, game, layout, interactive, joysticks, buttons">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<!-- Built-In Functions for Apps -->
<script type="text/javascript">
var localStoragePrefix = "ct-16811171866572";
var lastSave = 0;
// save to localstorage
function saveLocal(data) {
if (Date.now() - lastSave < 1000) {
return;
}
// save to cookie
let cookie = localStoragePrefix + "=" + JSON.stringify(data) + "; path=" + window.location.pathname + "'; SameSite=Strict";
cookie += "; expires=" + new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 * 1000).toUTCString();
document.cookie = cookie;
lastSave = Date.now();
}
// load from localstorage
function loadLocal() {
var cookiePrefix = localStoragePrefix + "=";
var cookieStart = document.cookie.indexOf(cookiePrefix);
if (cookieStart > -1) {
let cookieEnd = document.cookie.indexOf(";", cookieStart);
if (cookieEnd == -1) {
cookieEnd = document.cookie.length;
}
var cookieData = document.cookie.substring(cookieStart + cookiePrefix.length, cookieEnd);
return JSON.parse(cookieData);
}
}
</script>
<style>
body {
background-color: #2e2e2e;
font-family: "Arial", sans-serif;
}
#main-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
padding-top: 20px;
}
.joystick {
position: relative;
background-color: #4a4a4a;
border-radius: 50%;
width: 150px;
height: 150px;
margin: 20px;
display: flex;
align-items: center;
justify-content: center;
}
.thumbstick {
position: absolute;
background-color: #1f1f1f;
border-radius: 50%;
width: 75px;
height: 75px;
z-index: 1;
}
.button-container {
display: flex;
flex-direction: row;
margin-top: 20px;
}
.button {
background-color: #4a4a4a;
border-radius: 50%;
width: 75px;
height: 75px;
display: flex;
align-items: center;
justify-content: center;
margin: 20px;
color: #ffffff;
font-size: 30px;
}
</style>
<link rel="canonical" href="https://calculator.tools/prompt/59/">
<meta charset="utf-8">
</head>
<body>
<div id="main-container" class="container">
<!-- XBox Controller Layout -->
<div class="d-flex">
<div id="left-joystick" class="joystick">
<div id="left-thumbstick" class="thumbstick"></div>
</div>
<div id="right-joystick" class="joystick">
<div id="right-thumbstick" class="thumbstick"></div>
</div>
</div>
<div class="button-container">
<div class="button">A</div>
<div class="button">B</div>
<div class="button">X</div>
<div class="button">Y</div>
</div>
</div>
<script type="text/javascript">
function handleJoystickMove(joystick, thumbstick, event) {
const rect = joystick.getBoundingClientRect();
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
const maxDistance = rect.width / 4;
let x = event.clientX - centerX;
let y = event.clientY - centerY;
const distance = Math.sqrt(x * x + y * y);
if (distance > maxDistance) {
x = (x / distance) * maxDistance;
y = (y / distance) * maxDistance;
}
thumbstick.style.transform = `translate(${x}px, ${y}px)`;
}
function resetJoystickPosition(thumbstick) {
thumbstick.style.transform = "translate(0, 0)";
}
const leftJoystick = document.getElementById("left-joystick");
const leftThumbstick = document.getElementById("left-thumbstick");
leftJoystick.addEventListener("mousedown", (event) => {
event.preventDefault();
handleJoystickMove(leftJoystick, leftThumbstick, event);
leftJoystick.addEventListener("mousemove", handleJoystickMove.bind(null, leftJoystick, leftThumbstick));
});
leftJoystick.addEventListener("mouseup", () => {
resetJoystickPosition(leftThumbstick);
leftJoystick.removeEventListener("mousemove", handleJoystickMove);
});
leftJoystick.addEventListener("mouseleave", () => {
resetJoystickPosition(leftThumbstick);
leftJoystick.removeEventListener("mousemove", handleJoystickMove);
});
const rightJoystick = document.getElementById("right-joystick");
const rightThumbstick = document.getElementById("right-thumbstick");
rightJoystick.addEventListener("mousedown", (event) => {
event.preventDefault();
handleJoystickMove(rightJoystick, rightThumbstick, event);
rightJoystick.addEventListener("mousemove", handleJoystickMove.bind(null, rightJoystick, rightThumbstick));
});
rightJoystick.addEventListener("mouseup", () => {
resetJoystickPosition(rightThumbstick);
rightJoystick.removeEventListener("mousemove", handleJoystickMove);
});
rightJoystick.addEventListener("mouseleave", () => {
resetJoystickPosition(rightThumbstick);
rightJoystick.removeEventListener("mousemove", handleJoystickMove);
});
</script>
<script type="text/javascript"> var localStoragePrefix = "ct-{{ cachebreaker }}"; var lastSave = 0; function saveLocal(data) { if (Date.now() - lastSave < 1000) { return; } let cookie = localStoragePrefix + "=" + JSON.stringify(data) + "; path=" + window.location.pathname + "'; SameSite=Strict"; cookie += "; expires=" + new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 * 1000).toUTCString(); document.cookie = cookie; lastSave = Date.now(); } function loadLocal() { var cookiePrefix = localStoragePrefix + "="; var cookieStart = document.cookie.indexOf(cookiePrefix); if (cookieStart > -1) { let cookieEnd = document.cookie.indexOf(";", cookieStart); if (cookieEnd == -1) { cookieEnd = document.cookie.length; } var cookieData = document.cookie.substring(cookieStart + cookiePrefix.length, cookieEnd); return JSON.parse(cookieData); } } </script>
<script type="text/javascript"> window.addEventListener('load', function() { var observer = new MutationObserver(function() { window.parent.postMessage({height: document.documentElement.scrollHeight || document.body.scrollHeight},"*"); }); observer.observe(document.body, {attributes: true, childList: true, subtree: true}); window.parent.postMessage({height: document.documentElement.scrollHeight || document.body.scrollHeight},"*"); }); </script>
</body>
</html>