Reaperxxxx commited on
Commit
2ce3b01
·
verified ·
1 Parent(s): d135cc3

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +15 -20
script.js CHANGED
@@ -6,33 +6,29 @@ document.addEventListener("DOMContentLoaded", () => {
6
  const backBtn = document.getElementById("back-btn");
7
  const plane = document.getElementById("plane");
8
  const multiplierDisplay = document.getElementById("multiplier");
9
- const skyVideo = document.querySelector(".sky-video");
10
  const audio = new Audio("sound.mp3"); // Replace with your sound file path
11
 
12
- let balance = 100; // Default balance if no backend interaction
13
  let gameInterval;
14
  let multiplier = 1.0;
15
  let crashPoint = 0;
16
  let stakeAmount = 0;
17
- let gameId = null;
18
 
19
- // Play sky video and sound
20
- const playMedia = () => {
21
- if (skyVideo) skyVideo.play();
22
  if (audio) audio.play();
23
  };
24
 
25
- // Pause sky video and sound
26
- const stopMedia = () => {
27
- if (skyVideo) skyVideo.pause();
28
  if (audio) {
29
  audio.pause();
30
  audio.currentTime = 0; // Reset sound to the beginning
31
  }
32
  };
33
 
34
- // Place a stake and start the game
35
- const startGame = async () => {
36
  stakeAmount = parseFloat(stakeAmountInput.value);
37
 
38
  if (isNaN(stakeAmount) || stakeAmount <= 0 || stakeAmount > balance) {
@@ -49,12 +45,11 @@ document.addEventListener("DOMContentLoaded", () => {
49
  cashoutBtn.disabled = false;
50
  stakeBtn.disabled = true;
51
 
52
- // Start video and sound
53
- playMedia();
54
 
55
  // Start multiplier animation and plane movement
56
  gameInterval = setInterval(() => {
57
- multiplier += 0.1;
58
  multiplierDisplay.textContent = multiplier.toFixed(2) + "x";
59
 
60
  // Move the plane across the screen
@@ -63,10 +58,10 @@ document.addEventListener("DOMContentLoaded", () => {
63
  if (multiplier >= crashPoint) {
64
  clearInterval(gameInterval);
65
  alert("Plane crashed! You lost your stake.");
66
- stopMedia(); // Stop video and sound
67
  resetGame();
68
  }
69
- }, 100);
70
  };
71
 
72
  // Cash out before crash
@@ -78,11 +73,11 @@ document.addEventListener("DOMContentLoaded", () => {
78
  balanceDisplay.textContent = balance.toFixed(2);
79
 
80
  alert(`You cashed out at ${multiplier.toFixed(2)}x. Winnings: ${winnings.toFixed(2)}`);
81
- stopMedia(); // Stop video and sound
82
  resetGame();
83
  };
84
 
85
- // Reset game state
86
  const resetGame = () => {
87
  multiplierDisplay.textContent = "1.0x";
88
  plane.style.transform = "translateX(0px)";
@@ -94,9 +89,9 @@ document.addEventListener("DOMContentLoaded", () => {
94
  stakeBtn.addEventListener("click", startGame);
95
  cashoutBtn.addEventListener("click", cashout);
96
  backBtn.addEventListener("click", () => {
97
- window.location.href = "home";
98
  });
99
 
100
  // Initialize balance
101
  balanceDisplay.textContent = balance.toFixed(2);
102
- });
 
6
  const backBtn = document.getElementById("back-btn");
7
  const plane = document.getElementById("plane");
8
  const multiplierDisplay = document.getElementById("multiplier");
 
9
  const audio = new Audio("sound.mp3"); // Replace with your sound file path
10
 
11
+ let balance = 10000; // Default balance
12
  let gameInterval;
13
  let multiplier = 1.0;
14
  let crashPoint = 0;
15
  let stakeAmount = 0;
 
16
 
17
+ // Play sound
18
+ const playSound = () => {
 
19
  if (audio) audio.play();
20
  };
21
 
22
+ // Stop sound
23
+ const stopSound = () => {
 
24
  if (audio) {
25
  audio.pause();
26
  audio.currentTime = 0; // Reset sound to the beginning
27
  }
28
  };
29
 
30
+ // Start the game
31
+ const startGame = () => {
32
  stakeAmount = parseFloat(stakeAmountInput.value);
33
 
34
  if (isNaN(stakeAmount) || stakeAmount <= 0 || stakeAmount > balance) {
 
45
  cashoutBtn.disabled = false;
46
  stakeBtn.disabled = true;
47
 
48
+ playSound(); // Play sound when the game starts
 
49
 
50
  // Start multiplier animation and plane movement
51
  gameInterval = setInterval(() => {
52
+ multiplier += 0.05; // Slower multiplier increment
53
  multiplierDisplay.textContent = multiplier.toFixed(2) + "x";
54
 
55
  // Move the plane across the screen
 
58
  if (multiplier >= crashPoint) {
59
  clearInterval(gameInterval);
60
  alert("Plane crashed! You lost your stake.");
61
+ stopSound(); // Stop sound on crash
62
  resetGame();
63
  }
64
+ }, 200); // Slower interval for smoother animation
65
  };
66
 
67
  // Cash out before crash
 
73
  balanceDisplay.textContent = balance.toFixed(2);
74
 
75
  alert(`You cashed out at ${multiplier.toFixed(2)}x. Winnings: ${winnings.toFixed(2)}`);
76
+ stopSound(); // Stop sound on cash out
77
  resetGame();
78
  };
79
 
80
+ // Reset the game state
81
  const resetGame = () => {
82
  multiplierDisplay.textContent = "1.0x";
83
  plane.style.transform = "translateX(0px)";
 
89
  stakeBtn.addEventListener("click", startGame);
90
  cashoutBtn.addEventListener("click", cashout);
91
  backBtn.addEventListener("click", () => {
92
+ window.location.href = "home"; // Replace with your actual back button URL
93
  });
94
 
95
  // Initialize balance
96
  balanceDisplay.textContent = balance.toFixed(2);
97
+ });