Update index.html
Browse files- index.html +48 -2
index.html
CHANGED
@@ -11,16 +11,30 @@
|
|
11 |
<div id="ball" class="ball"></div>
|
12 |
<div id="platform" class="platform"></div>
|
13 |
<div id="score">Score: 0</div>
|
|
|
14 |
</div>
|
|
|
|
|
|
|
|
|
|
|
15 |
<script>
|
16 |
let ball = document.getElementById("ball");
|
17 |
let platform = document.getElementById("platform");
|
18 |
let score = document.getElementById("score");
|
19 |
-
let
|
|
|
|
|
20 |
|
|
|
|
|
|
|
21 |
let platformX = window.innerWidth / 2 - 50;
|
22 |
platform.style.left = platformX + "px";
|
23 |
|
|
|
|
|
|
|
24 |
document.addEventListener("mousemove", (e) => {
|
25 |
platformX = e.clientX - platform.offsetWidth / 2;
|
26 |
if (platformX < 0) platformX = 0;
|
@@ -30,10 +44,31 @@
|
|
30 |
platform.style.left = platformX + "px";
|
31 |
});
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
let dropBall = () => {
|
34 |
let ballX = Math.floor(Math.random() * (window.innerWidth - 30));
|
35 |
ball.style.left = ballX + "px";
|
36 |
-
ball.style.animation =
|
37 |
};
|
38 |
|
39 |
ball.addEventListener("animationiteration", () => {
|
@@ -43,12 +78,23 @@
|
|
43 |
if (ballPosition.bottom >= platformPosition.top &&
|
44 |
ballPosition.left >= platformPosition.left &&
|
45 |
ballPosition.right <= platformPosition.right) {
|
|
|
46 |
currentScore++;
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
score.innerHTML = "Score: " + currentScore;
|
48 |
dropBall();
|
49 |
} else if (ballPosition.bottom >= window.innerHeight) {
|
|
|
50 |
currentScore = 0;
|
|
|
|
|
51 |
score.innerHTML = "Score: " + currentScore;
|
|
|
52 |
dropBall();
|
53 |
}
|
54 |
});
|
|
|
11 |
<div id="ball" class="ball"></div>
|
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 |
+
<!-- Adding sound effects -->
|
18 |
+
<audio id="bounce-sound" src="bounce-sound.mp3" preload="auto"></audio>
|
19 |
+
<audio id="game-over-sound" src="game-over.mp3" preload="auto"></audio>
|
20 |
+
|
21 |
<script>
|
22 |
let ball = document.getElementById("ball");
|
23 |
let platform = document.getElementById("platform");
|
24 |
let score = document.getElementById("score");
|
25 |
+
let levelDisplay = document.getElementById("level");
|
26 |
+
let bounceSound = document.getElementById("bounce-sound");
|
27 |
+
let gameOverSound = document.getElementById("game-over-sound");
|
28 |
|
29 |
+
let currentScore = 0;
|
30 |
+
let level = 1;
|
31 |
+
let fallSpeed = 3; // Initial fall speed (seconds)
|
32 |
let platformX = window.innerWidth / 2 - 50;
|
33 |
platform.style.left = platformX + "px";
|
34 |
|
35 |
+
let isTouching = false;
|
36 |
+
|
37 |
+
// Kontrol menggunakan Mouse
|
38 |
document.addEventListener("mousemove", (e) => {
|
39 |
platformX = e.clientX - platform.offsetWidth / 2;
|
40 |
if (platformX < 0) platformX = 0;
|
|
|
44 |
platform.style.left = platformX + "px";
|
45 |
});
|
46 |
|
47 |
+
// Kontrol menggunakan Sentuhan
|
48 |
+
document.addEventListener("touchmove", (e) => {
|
49 |
+
if (isTouching) {
|
50 |
+
let touchX = e.touches[0].clientX;
|
51 |
+
platformX = touchX - platform.offsetWidth / 2;
|
52 |
+
if (platformX < 0) platformX = 0;
|
53 |
+
if (platformX > window.innerWidth - platform.offsetWidth) {
|
54 |
+
platformX = window.innerWidth - platform.offsetWidth;
|
55 |
+
}
|
56 |
+
platform.style.left = platformX + "px";
|
57 |
+
}
|
58 |
+
}, { passive: false });
|
59 |
+
|
60 |
+
document.addEventListener("touchstart", (e) => {
|
61 |
+
isTouching = true;
|
62 |
+
});
|
63 |
+
|
64 |
+
document.addEventListener("touchend", (e) => {
|
65 |
+
isTouching = false;
|
66 |
+
});
|
67 |
+
|
68 |
let dropBall = () => {
|
69 |
let ballX = Math.floor(Math.random() * (window.innerWidth - 30));
|
70 |
ball.style.left = ballX + "px";
|
71 |
+
ball.style.animation = `fall ${fallSpeed}s linear infinite`;
|
72 |
};
|
73 |
|
74 |
ball.addEventListener("animationiteration", () => {
|
|
|
78 |
if (ballPosition.bottom >= platformPosition.top &&
|
79 |
ballPosition.left >= platformPosition.left &&
|
80 |
ballPosition.right <= platformPosition.right) {
|
81 |
+
bounceSound.play(); // Play bounce sound
|
82 |
currentScore++;
|
83 |
+
if (currentScore % 10 === 0) {
|
84 |
+
level++;
|
85 |
+
levelDisplay.innerHTML = "Level: " + level;
|
86 |
+
fallSpeed -= 0.2;
|
87 |
+
dropBall(); // Drop ball again with updated speed
|
88 |
+
}
|
89 |
score.innerHTML = "Score: " + currentScore;
|
90 |
dropBall();
|
91 |
} else if (ballPosition.bottom >= window.innerHeight) {
|
92 |
+
gameOverSound.play(); // Play game over sound
|
93 |
currentScore = 0;
|
94 |
+
level = 1;
|
95 |
+
fallSpeed = 3; // Reset fall speed
|
96 |
score.innerHTML = "Score: " + currentScore;
|
97 |
+
levelDisplay.innerHTML = "Level: " + level;
|
98 |
dropBall();
|
99 |
}
|
100 |
});
|