Update index.html
Browse files- index.html +14 -4
index.html
CHANGED
|
@@ -11,20 +11,30 @@
|
|
| 11 |
<div class="ball"></div>
|
| 12 |
<div class="platform"></div>
|
| 13 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
<script>
|
| 15 |
const platform = document.querySelector('.platform');
|
| 16 |
const ball = document.querySelector('.ball');
|
| 17 |
const gameContainer = document.querySelector('.game-container');
|
|
|
|
|
|
|
| 18 |
|
| 19 |
let platformPosition = 50; // Initial position of the platform (centered).
|
| 20 |
let ballPosition = { top: 0, left: Math.random() * 90 }; // Random horizontal start for the ball.
|
| 21 |
|
| 22 |
-
//
|
| 23 |
-
|
| 24 |
-
if (
|
| 25 |
platformPosition -= 5; // Move left
|
| 26 |
}
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
platformPosition += 5; // Move right
|
| 29 |
}
|
| 30 |
platform.style.left = platformPosition + '%';
|
|
|
|
| 11 |
<div class="ball"></div>
|
| 12 |
<div class="platform"></div>
|
| 13 |
</div>
|
| 14 |
+
<div class="controls">
|
| 15 |
+
<button id="left-button">◀</button>
|
| 16 |
+
<button id="right-button">▶</button>
|
| 17 |
+
</div>
|
| 18 |
<script>
|
| 19 |
const platform = document.querySelector('.platform');
|
| 20 |
const ball = document.querySelector('.ball');
|
| 21 |
const gameContainer = document.querySelector('.game-container');
|
| 22 |
+
const leftButton = document.getElementById('left-button');
|
| 23 |
+
const rightButton = document.getElementById('right-button');
|
| 24 |
|
| 25 |
let platformPosition = 50; // Initial position of the platform (centered).
|
| 26 |
let ballPosition = { top: 0, left: Math.random() * 90 }; // Random horizontal start for the ball.
|
| 27 |
|
| 28 |
+
// Mobile controls
|
| 29 |
+
leftButton.addEventListener('click', () => {
|
| 30 |
+
if (platformPosition > 0) {
|
| 31 |
platformPosition -= 5; // Move left
|
| 32 |
}
|
| 33 |
+
platform.style.left = platformPosition + '%';
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
rightButton.addEventListener('click', () => {
|
| 37 |
+
if (platformPosition < 90) {
|
| 38 |
platformPosition += 5; // Move right
|
| 39 |
}
|
| 40 |
platform.style.left = platformPosition + '%';
|