GarGerry commited on
Commit
a7c28a1
·
verified ·
1 Parent(s): 0c7940f

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +12 -24
index.html CHANGED
@@ -4,7 +4,7 @@
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Futuristic Falling Ball Game</title>
7
- <link rel="stylesheet" href="style.css"> <!-- Link ke file CSS terpisah -->
8
  </head>
9
  <body>
10
  <div class="game-container">
@@ -13,10 +13,10 @@
13
  <div id="score">Score: 0</div>
14
  <div id="level">Level: 1</div>
15
  <div id="lives">
16
- <span class="life" id="life1">♥️</span>
17
- <span class="life" id="life2">♥️</span>
18
- <span class="life" id="life3">♥️</span>
19
- <span class="life" id="life4">♥️</span>
20
  </div>
21
  </div>
22
 
@@ -36,7 +36,7 @@
36
  let remainingLives = 4;
37
  let ballY = -30;
38
  let ballX = Math.floor(Math.random() * (window.innerWidth - 30));
39
- let ballSpeed = 2; // Ball fall speed per frame
40
  let isTouching = false;
41
 
42
  // Kontrol menggunakan Mouse
@@ -71,14 +71,11 @@
71
  });
72
 
73
  let updateLives = () => {
74
- for (let i = 1; i <= 4; i++) {
75
- let life = document.getElementById(`life${i}`);
76
- if (i > remainingLives) {
77
- life.style.visibility = "hidden";
78
- } else {
79
- life.style.visibility = "visible";
80
- }
81
  }
 
82
  };
83
 
84
  let updateBallPosition = () => {
@@ -91,20 +88,17 @@
91
  let ballRect = ball.getBoundingClientRect();
92
  let platformRect = platform.getBoundingClientRect();
93
 
94
- // Cek jika bola mengenai platform
95
  if (ballY + 30 >= platformRect.top && ballY + 30 <= platformRect.bottom) {
96
  if (ballX + 30 >= platformRect.left && ballX <= platformRect.right) {
97
  // Ball hits the platform
98
  currentScore++;
99
- score.innerHTML = "Score: " + currentScore;
100
-
101
- // Level Up Logic
102
  if (currentScore % 10 === 0) {
103
  level++;
104
  levelDisplay.innerHTML = "Level: " + level;
105
  fallSpeed -= 0.2;
106
  ballSpeed += 0.1; // Make ball fall faster
107
  }
 
108
  resetBall();
109
  }
110
  } else if (ballY >= window.innerHeight) {
@@ -120,12 +114,6 @@
120
  };
121
 
122
  let resetBall = () => {
123
- // Stop the animation when ball is reset
124
- ball.style.animation = 'none';
125
- setTimeout(() => {
126
- ball.style.animation = `fall ${fallSpeed}s linear infinite`;
127
- }, 50); // Delay to restart the animation
128
-
129
  ballY = -30; // Reset ball to start position
130
  ballX = Math.floor(Math.random() * (window.innerWidth - 30)); // New random X position
131
  ball.style.top = ballY + "px";
@@ -136,7 +124,7 @@
136
  remainingLives = 4;
137
  currentScore = 0;
138
  level = 1;
139
- ballSpeed = 2;
140
  fallSpeed = 3;
141
  score.innerHTML = "Score: " + currentScore;
142
  levelDisplay.innerHTML = "Level: " + level;
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Futuristic Falling Ball Game</title>
7
+ <link rel="stylesheet" href="style.css">
8
  </head>
9
  <body>
10
  <div class="game-container">
 
13
  <div id="score">Score: 0</div>
14
  <div id="level">Level: 1</div>
15
  <div id="lives">
16
+ <span class="life">♥️</span>
17
+ <span class="life">♥️</span>
18
+ <span class="life">♥️</span>
19
+ <span class="life">♥️</span>
20
  </div>
21
  </div>
22
 
 
36
  let remainingLives = 4;
37
  let ballY = -30;
38
  let ballX = Math.floor(Math.random() * (window.innerWidth - 30));
39
+ let ballSpeed = 5; // Ball fall speed per frame
40
  let isTouching = false;
41
 
42
  // Kontrol menggunakan Mouse
 
71
  });
72
 
73
  let updateLives = () => {
74
+ let hearts = '';
75
+ for (let i = 0; i < remainingLives; i++) {
76
+ hearts += '♥️';
 
 
 
 
77
  }
78
+ livesDisplay.innerHTML = hearts;
79
  };
80
 
81
  let updateBallPosition = () => {
 
88
  let ballRect = ball.getBoundingClientRect();
89
  let platformRect = platform.getBoundingClientRect();
90
 
 
91
  if (ballY + 30 >= platformRect.top && ballY + 30 <= platformRect.bottom) {
92
  if (ballX + 30 >= platformRect.left && ballX <= platformRect.right) {
93
  // Ball hits the platform
94
  currentScore++;
 
 
 
95
  if (currentScore % 10 === 0) {
96
  level++;
97
  levelDisplay.innerHTML = "Level: " + level;
98
  fallSpeed -= 0.2;
99
  ballSpeed += 0.1; // Make ball fall faster
100
  }
101
+ score.innerHTML = "Score: " + currentScore;
102
  resetBall();
103
  }
104
  } else if (ballY >= window.innerHeight) {
 
114
  };
115
 
116
  let resetBall = () => {
 
 
 
 
 
 
117
  ballY = -30; // Reset ball to start position
118
  ballX = Math.floor(Math.random() * (window.innerWidth - 30)); // New random X position
119
  ball.style.top = ballY + "px";
 
124
  remainingLives = 4;
125
  currentScore = 0;
126
  level = 1;
127
+ ballSpeed = 5;
128
  fallSpeed = 3;
129
  score.innerHTML = "Score: " + currentScore;
130
  levelDisplay.innerHTML = "Level: " + level;