Update index.html
Browse files- index.html +15 -24
index.html
CHANGED
@@ -41,6 +41,7 @@
|
|
41 |
let ballPosition = { top: 0, left: Math.random() * 90 }; // Bola muncul secara acak.
|
42 |
let isCaught = false; // Apakah bola ditangkap.
|
43 |
let score = 0; // Skor awal.
|
|
|
44 |
|
45 |
// Fungsi untuk memindahkan platform ke kiri
|
46 |
function movePlatformLeft() {
|
@@ -85,7 +86,7 @@
|
|
85 |
// Fungsi untuk menggerakkan bola
|
86 |
function moveBall() {
|
87 |
if (isCaught) return; // Jangan lanjut jika bola ditangkap.
|
88 |
-
ballPosition.top +=
|
89 |
ball.style.top = ballPosition.top + '%';
|
90 |
ball.style.left = ballPosition.left + '%';
|
91 |
|
@@ -94,6 +95,7 @@
|
|
94 |
isCaught = true;
|
95 |
score++; // Tambahkan skor.
|
96 |
scoreDisplay.textContent = score; // Update skor di layar.
|
|
|
97 |
resetGame();
|
98 |
}
|
99 |
|
@@ -108,29 +110,18 @@
|
|
108 |
requestAnimationFrame(moveBall);
|
109 |
}
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
// Fungsi untuk mereset permainan
|
112 |
function resetGame() {
|
113 |
isCaught = false;
|
114 |
-
ballPosition = { top
|
115 |
-
}
|
116 |
-
|
117 |
-
// Fungsi untuk menampilkan overlay Game Over
|
118 |
-
function showGameOver() {
|
119 |
-
finalScoreDisplay.textContent = score; // Tampilkan skor akhir.
|
120 |
-
overlay.style.display = 'flex'; // Tampilkan overlay.
|
121 |
-
}
|
122 |
-
|
123 |
-
// Tombol restart untuk memulai ulang permainan
|
124 |
-
restartButton.addEventListener('click', () => {
|
125 |
-
overlay.style.display = 'none'; // Sembunyikan overlay.
|
126 |
-
score = 0; // Reset skor.
|
127 |
-
scoreDisplay.textContent = score;
|
128 |
-
resetGame();
|
129 |
-
moveBall();
|
130 |
-
});
|
131 |
-
|
132 |
-
// Memulai permainan
|
133 |
-
moveBall();
|
134 |
-
</script>
|
135 |
-
</body>
|
136 |
-
</html>
|
|
|
41 |
let ballPosition = { top: 0, left: Math.random() * 90 }; // Bola muncul secara acak.
|
42 |
let isCaught = false; // Apakah bola ditangkap.
|
43 |
let score = 0; // Skor awal.
|
44 |
+
let ballSpeed = 1.5; // Kecepatan bola
|
45 |
|
46 |
// Fungsi untuk memindahkan platform ke kiri
|
47 |
function movePlatformLeft() {
|
|
|
86 |
// Fungsi untuk menggerakkan bola
|
87 |
function moveBall() {
|
88 |
if (isCaught) return; // Jangan lanjut jika bola ditangkap.
|
89 |
+
ballPosition.top += ballSpeed; // Bola turun.
|
90 |
ball.style.top = ballPosition.top + '%';
|
91 |
ball.style.left = ballPosition.left + '%';
|
92 |
|
|
|
95 |
isCaught = true;
|
96 |
score++; // Tambahkan skor.
|
97 |
scoreDisplay.textContent = score; // Update skor di layar.
|
98 |
+
adjustBallSpeed(); // Sesuaikan kecepatan bola berdasarkan skor.
|
99 |
resetGame();
|
100 |
}
|
101 |
|
|
|
110 |
requestAnimationFrame(moveBall);
|
111 |
}
|
112 |
|
113 |
+
// Fungsi untuk menyesuaikan kecepatan bola berdasarkan skor
|
114 |
+
function adjustBallSpeed() {
|
115 |
+
if (score > 20) {
|
116 |
+
ballSpeed = 2.5; // Meningkatkan kecepatan bola jika skor lebih dari 20
|
117 |
+
} else if (score > 10) {
|
118 |
+
ballSpeed = 2.0; // Kecepatan sedikit meningkat setelah skor 10
|
119 |
+
} else {
|
120 |
+
ballSpeed = 1.5; // Kecepatan bola di awal
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
// Fungsi untuk mereset permainan
|
125 |
function resetGame() {
|
126 |
isCaught = false;
|
127 |
+
ballPosition = { top
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|