Update index.html
Browse files- index.html +57 -25
index.html
CHANGED
|
@@ -8,14 +8,29 @@
|
|
| 8 |
</head>
|
| 9 |
<body>
|
| 10 |
<div class="game-container">
|
| 11 |
-
<
|
| 12 |
-
<div id="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
<div id="score">Score: 0</div>
|
| 14 |
<div id="level">Level: 1</div>
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</div>
|
| 20 |
</div>
|
| 21 |
|
|
@@ -25,16 +40,19 @@
|
|
| 25 |
let score = document.getElementById("score");
|
| 26 |
let levelDisplay = document.getElementById("level");
|
| 27 |
let livesDisplay = document.getElementById("lives");
|
|
|
|
|
|
|
| 28 |
|
| 29 |
let currentScore = 0;
|
| 30 |
let level = 1;
|
|
|
|
| 31 |
let platformX = window.innerWidth / 2 - 50;
|
| 32 |
platform.style.left = platformX + "px";
|
| 33 |
|
| 34 |
-
let remainingLives =
|
| 35 |
let ballY = -30;
|
| 36 |
let ballX = Math.floor(Math.random() * (window.innerWidth - 30));
|
| 37 |
-
let ballSpeed =
|
| 38 |
let isTouching = false;
|
| 39 |
|
| 40 |
// Kontrol menggunakan Mouse
|
|
@@ -69,17 +87,20 @@
|
|
| 69 |
});
|
| 70 |
|
| 71 |
let updateLives = () => {
|
| 72 |
-
let
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
}
|
| 76 |
-
livesDisplay.innerHTML = hearts;
|
| 77 |
};
|
| 78 |
|
| 79 |
let updateBallPosition = () => {
|
| 80 |
ballY += ballSpeed;
|
| 81 |
|
| 82 |
-
// Update ball position
|
| 83 |
ball.style.top = ballY + "px";
|
| 84 |
ball.style.left = ballX + "px";
|
| 85 |
|
|
@@ -93,42 +114,53 @@
|
|
| 93 |
if (currentScore % 10 === 0) {
|
| 94 |
level++;
|
| 95 |
levelDisplay.innerHTML = "Level: " + level;
|
| 96 |
-
|
|
|
|
| 97 |
}
|
| 98 |
score.innerHTML = "Score: " + currentScore;
|
| 99 |
resetBall();
|
| 100 |
}
|
| 101 |
} else if (ballY >= window.innerHeight) {
|
| 102 |
// Ball missed the platform
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
updateLives();
|
| 106 |
-
resetBall();
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
if (remainingLives <= 0) {
|
| 110 |
-
|
| 111 |
-
resetGame();
|
| 112 |
}
|
|
|
|
| 113 |
}
|
| 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";
|
| 120 |
ball.style.left = ballX + "px";
|
| 121 |
};
|
| 122 |
|
| 123 |
-
let
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
currentScore = 0;
|
| 126 |
level = 1;
|
| 127 |
-
ballSpeed =
|
|
|
|
| 128 |
score.innerHTML = "Score: " + currentScore;
|
| 129 |
levelDisplay.innerHTML = "Level: " + level;
|
| 130 |
updateLives();
|
|
|
|
| 131 |
resetBall();
|
|
|
|
| 132 |
};
|
| 133 |
|
| 134 |
let gameLoop = () => {
|
|
|
|
| 8 |
</head>
|
| 9 |
<body>
|
| 10 |
<div class="game-container">
|
| 11 |
+
<!-- Nyawa (♥️) ditempatkan di bagian atas layar -->
|
| 12 |
+
<div id="lives">
|
| 13 |
+
<span class="life">❤️</span>
|
| 14 |
+
<span class="life">❤️</span>
|
| 15 |
+
<span class="life">❤️</span>
|
| 16 |
+
<span class="life">❤️</span>
|
| 17 |
+
</div>
|
| 18 |
+
|
| 19 |
+
<!-- Skor dan Level di posisi kiri dan kanan atas -->
|
| 20 |
<div id="score">Score: 0</div>
|
| 21 |
<div id="level">Level: 1</div>
|
| 22 |
+
|
| 23 |
+
<!-- Platform yang dikendalikan oleh pemain -->
|
| 24 |
+
<div id="platform" class="platform"></div>
|
| 25 |
+
|
| 26 |
+
<!-- Bola yang akan jatuh -->
|
| 27 |
+
<div id="ball" class="ball"></div>
|
| 28 |
+
|
| 29 |
+
<!-- Game Over -->
|
| 30 |
+
<div id="game-over" class="game-over">
|
| 31 |
+
<h2>Game Over!</h2>
|
| 32 |
+
<p>Your Score: <span id="final-score">0</span></p>
|
| 33 |
+
<button id="restart-btn" onclick="restartGame()">Restart</button>
|
| 34 |
</div>
|
| 35 |
</div>
|
| 36 |
|
|
|
|
| 40 |
let score = document.getElementById("score");
|
| 41 |
let levelDisplay = document.getElementById("level");
|
| 42 |
let livesDisplay = document.getElementById("lives");
|
| 43 |
+
let gameOverDisplay = document.getElementById("game-over");
|
| 44 |
+
let finalScoreDisplay = document.getElementById("final-score");
|
| 45 |
|
| 46 |
let currentScore = 0;
|
| 47 |
let level = 1;
|
| 48 |
+
let fallSpeed = 3; // Initial fall speed (seconds)
|
| 49 |
let platformX = window.innerWidth / 2 - 50;
|
| 50 |
platform.style.left = platformX + "px";
|
| 51 |
|
| 52 |
+
let remainingLives = 4;
|
| 53 |
let ballY = -30;
|
| 54 |
let ballX = Math.floor(Math.random() * (window.innerWidth - 30));
|
| 55 |
+
let ballSpeed = 2; // Ball fall speed per frame
|
| 56 |
let isTouching = false;
|
| 57 |
|
| 58 |
// Kontrol menggunakan Mouse
|
|
|
|
| 87 |
});
|
| 88 |
|
| 89 |
let updateLives = () => {
|
| 90 |
+
for (let i = 1; i <= 4; i++) {
|
| 91 |
+
let life = document.getElementById(`life${i}`);
|
| 92 |
+
if (i > remainingLives) {
|
| 93 |
+
life.style.visibility = "hidden";
|
| 94 |
+
} else {
|
| 95 |
+
life.style.visibility = "visible";
|
| 96 |
+
}
|
| 97 |
}
|
|
|
|
| 98 |
};
|
| 99 |
|
| 100 |
let updateBallPosition = () => {
|
| 101 |
ballY += ballSpeed;
|
| 102 |
|
| 103 |
+
// Update ball position
|
| 104 |
ball.style.top = ballY + "px";
|
| 105 |
ball.style.left = ballX + "px";
|
| 106 |
|
|
|
|
| 114 |
if (currentScore % 10 === 0) {
|
| 115 |
level++;
|
| 116 |
levelDisplay.innerHTML = "Level: " + level;
|
| 117 |
+
fallSpeed -= 0.2;
|
| 118 |
+
ballSpeed += 0.1; // Make ball fall faster
|
| 119 |
}
|
| 120 |
score.innerHTML = "Score: " + currentScore;
|
| 121 |
resetBall();
|
| 122 |
}
|
| 123 |
} else if (ballY >= window.innerHeight) {
|
| 124 |
// Ball missed the platform
|
| 125 |
+
remainingLives--;
|
| 126 |
+
updateLives();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
if (remainingLives <= 0) {
|
| 128 |
+
gameOver();
|
|
|
|
| 129 |
}
|
| 130 |
+
resetBall();
|
| 131 |
}
|
| 132 |
};
|
| 133 |
|
| 134 |
let resetBall = () => {
|
| 135 |
+
// Stop the animation when ball is reset
|
| 136 |
+
ball.style.animation = 'none';
|
| 137 |
+
setTimeout(() => {
|
| 138 |
+
ball.style.animation = `fall ${fallSpeed}s linear infinite`;
|
| 139 |
+
}, 50); // Delay to restart the animation
|
| 140 |
+
|
| 141 |
ballY = -30; // Reset ball to start position
|
| 142 |
ballX = Math.floor(Math.random() * (window.innerWidth - 30)); // New random X position
|
| 143 |
ball.style.top = ballY + "px";
|
| 144 |
ball.style.left = ballX + "px";
|
| 145 |
};
|
| 146 |
|
| 147 |
+
let gameOver = () => {
|
| 148 |
+
finalScoreDisplay.textContent = currentScore;
|
| 149 |
+
gameOverDisplay.style.display = "block";
|
| 150 |
+
};
|
| 151 |
+
|
| 152 |
+
let restartGame = () => {
|
| 153 |
+
remainingLives = 4;
|
| 154 |
currentScore = 0;
|
| 155 |
level = 1;
|
| 156 |
+
ballSpeed = 2;
|
| 157 |
+
fallSpeed = 3;
|
| 158 |
score.innerHTML = "Score: " + currentScore;
|
| 159 |
levelDisplay.innerHTML = "Level: " + level;
|
| 160 |
updateLives();
|
| 161 |
+
gameOverDisplay.style.display = "none";
|
| 162 |
resetBall();
|
| 163 |
+
gameLoop();
|
| 164 |
};
|
| 165 |
|
| 166 |
let gameLoop = () => {
|