Update index.html
Browse files- index.html +31 -5
index.html
CHANGED
@@ -12,6 +12,12 @@
|
|
12 |
<div id="platform" class="platform"></div>
|
13 |
<div id="score">Score: 0</div>
|
14 |
<div id="level">Level: 1</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
</div>
|
16 |
|
17 |
<script>
|
@@ -19,6 +25,7 @@
|
|
19 |
let platform = document.getElementById("platform");
|
20 |
let score = document.getElementById("score");
|
21 |
let levelDisplay = document.getElementById("level");
|
|
|
22 |
|
23 |
let currentScore = 0;
|
24 |
let level = 1;
|
@@ -26,6 +33,7 @@
|
|
26 |
let platformX = window.innerWidth / 2 - 50;
|
27 |
platform.style.left = platformX + "px";
|
28 |
|
|
|
29 |
let isTouching = false;
|
30 |
|
31 |
// Kontrol menggunakan Mouse
|
@@ -65,6 +73,17 @@
|
|
65 |
ball.style.animation = `fall ${fallSpeed}s linear infinite`;
|
66 |
};
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
ball.addEventListener("animationiteration", () => {
|
69 |
let ballPosition = ball.getBoundingClientRect();
|
70 |
let platformPosition = platform.getBoundingClientRect();
|
@@ -82,11 +101,18 @@
|
|
82 |
score.innerHTML = "Score: " + currentScore;
|
83 |
dropBall();
|
84 |
} else if (ballPosition.bottom >= window.innerHeight) {
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
dropBall();
|
91 |
}
|
92 |
});
|
|
|
12 |
<div id="platform" class="platform"></div>
|
13 |
<div id="score">Score: 0</div>
|
14 |
<div id="level">Level: 1</div>
|
15 |
+
<div id="lives">
|
16 |
+
<img class="life" src="life-icon.png" alt="Life" id="life1">
|
17 |
+
<img class="life" src="life-icon.png" alt="Life" id="life2">
|
18 |
+
<img class="life" src="life-icon.png" alt="Life" id="life3">
|
19 |
+
<img class="life" src="life-icon.png" alt="Life" id="life4">
|
20 |
+
</div>
|
21 |
</div>
|
22 |
|
23 |
<script>
|
|
|
25 |
let platform = document.getElementById("platform");
|
26 |
let score = document.getElementById("score");
|
27 |
let levelDisplay = document.getElementById("level");
|
28 |
+
let livesDisplay = document.getElementById("lives");
|
29 |
|
30 |
let currentScore = 0;
|
31 |
let level = 1;
|
|
|
33 |
let platformX = window.innerWidth / 2 - 50;
|
34 |
platform.style.left = platformX + "px";
|
35 |
|
36 |
+
let remainingLives = 4;
|
37 |
let isTouching = false;
|
38 |
|
39 |
// Kontrol menggunakan Mouse
|
|
|
73 |
ball.style.animation = `fall ${fallSpeed}s linear infinite`;
|
74 |
};
|
75 |
|
76 |
+
let updateLives = () => {
|
77 |
+
for (let i = 1; i <= 4; i++) {
|
78 |
+
let life = document.getElementById(`life${i}`);
|
79 |
+
if (i > remainingLives) {
|
80 |
+
life.style.visibility = "hidden";
|
81 |
+
} else {
|
82 |
+
life.style.visibility = "visible";
|
83 |
+
}
|
84 |
+
}
|
85 |
+
};
|
86 |
+
|
87 |
ball.addEventListener("animationiteration", () => {
|
88 |
let ballPosition = ball.getBoundingClientRect();
|
89 |
let platformPosition = platform.getBoundingClientRect();
|
|
|
101 |
score.innerHTML = "Score: " + currentScore;
|
102 |
dropBall();
|
103 |
} else if (ballPosition.bottom >= window.innerHeight) {
|
104 |
+
remainingLives--;
|
105 |
+
updateLives();
|
106 |
+
if (remainingLives <= 0) {
|
107 |
+
alert("Game Over! Your score is: " + currentScore);
|
108 |
+
remainingLives = 4; // Reset lives
|
109 |
+
currentScore = 0; // Reset score
|
110 |
+
level = 1; // Reset level
|
111 |
+
fallSpeed = 3; // Reset fall speed
|
112 |
+
score.innerHTML = "Score: " + currentScore;
|
113 |
+
levelDisplay.innerHTML = "Level: " + level;
|
114 |
+
updateLives();
|
115 |
+
}
|
116 |
dropBall();
|
117 |
}
|
118 |
});
|