Au / scripts.js
Reaperxxxx's picture
Create scripts.js
a6b6ac5 verified
Raw
History Blame Contribute Delete
2.02 kB
let balance = 100;
let multiplier = 1.0;
let isFlying = false;
let crashPoint = 0;
const balanceDisplay = document.getElementById("balance");
const multiplierDisplay = document.getElementById("multiplier");
const startGameButton = document.getElementById("start-game");
const cashOutButton = document.getElementById("cash-out");
const plane = document.getElementById("plane");
// Update balance display
function updateBalance() {
balanceDisplay.textContent = balance.toFixed(2);
}
// Reset plane position
function resetPlane() {
plane.style.left = "0";
}
// Move the plane
function movePlane(multiplier) {
const maxWidth = document.getElementById("game-area").offsetWidth - plane.offsetWidth;
const newLeft = Math.min(maxWidth, (multiplier / 5) * maxWidth); // Adjust scaling factor
plane.style.left = `${newLeft}px`;
}
// Start the game
startGameButton.addEventListener("click", () => {
if (isFlying) return;
crashPoint = (Math.random() * 5 + 1).toFixed(2); // Random crash point
isFlying = true;
multiplier = 1.0;
startGameButton.disabled = true;
cashOutButton.disabled = false;
resetPlane();
// Multiplier increase loop
const flightInterval = setInterval(() => {
if (multiplier >= crashPoint) {
clearInterval(flightInterval);
isFlying = false;
alert("Crashed! You lost your stake.");
resetGame();
} else {
multiplier += 0.1;
multiplierDisplay.textContent = multiplier.toFixed(2) + "x";
movePlane(multiplier);
}
}, 100);
});
// Cash out
cashOutButton.addEventListener("click", () => {
if (!isFlying) return;
isFlying = false;
balance += (multiplier - 1) * 10; // Example: stake of 10
updateBalance();
alert(`You cashed out at ${multiplier.toFixed(2)}x!`);
resetGame();
});
// Reset game
function resetGame() {
startGameButton.disabled = false;
cashOutButton.disabled = true;
multiplier = 1.0;
multiplierDisplay.textContent = "1.00x";
resetPlane();
}
// Initialize balance display
updateBalance();