GarGerry commited on
Commit
78ba153
·
verified ·
1 Parent(s): ff4924d

Update index.html

Browse files
Files changed (1) hide show
  1. 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
- // Move platform
23
- window.addEventListener('keydown', (e) => {
24
- if (e.key === 'ArrowLeft' && platformPosition > 0) {
25
  platformPosition -= 5; // Move left
26
  }
27
- if (e.key === 'ArrowRight' && platformPosition < 90) {
 
 
 
 
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 + '%';