dannyboy84 commited on
Commit
5d24137
Β·
verified Β·
1 Parent(s): 7f06df5

Make it have down left up right

Browse files
Files changed (2) hide show
  1. index.html +4 -4
  2. script.js +13 -4
index.html CHANGED
@@ -24,8 +24,8 @@
24
  <button id="startBtn" class="px-8 py-3 bg-gradient-to-r from-purple-600 to-blue-600 rounded-full text-white font-bold text-lg hover:scale-105 transition-transform shadow-lg hover:shadow-purple-500/50">
25
  Start Game
26
  </button>
27
- <p class="text-sm text-gray-300">Use arrow keys or swipe to move</p>
28
- </div>
29
  </div>
30
  <div id="gameOverScreen" class="absolute inset-0 hidden flex-col items-center justify-center bg-black bg-opacity-70 z-10">
31
  <h1 class="text-4xl md:text-5xl font-bold mb-4 text-red-400">Game Over</h1>
@@ -34,8 +34,8 @@
34
  <button id="restartBtn" class="px-8 py-3 bg-gradient-to-r from-purple-600 to-blue-600 rounded-full text-white font-bold text-lg hover:scale-105 transition-transform shadow-lg hover:shadow-purple-500/50">
35
  Try Again
36
  </button>
37
- <p class="text-sm text-gray-300">Use arrow keys or swipe to move</p>
38
- </div>
39
  </div>
40
  </div>
41
  <div class="mt-8 w-full max-w-4xl bg-black bg-opacity-30 rounded-2xl p-6 border border-purple-400 border-opacity-30">
 
24
  <button id="startBtn" class="px-8 py-3 bg-gradient-to-r from-purple-600 to-blue-600 rounded-full text-white font-bold text-lg hover:scale-105 transition-transform shadow-lg hover:shadow-purple-500/50">
25
  Start Game
26
  </button>
27
+ <p class="text-sm text-gray-300">Use arrow keys (←↑→↓) or swipe to move</p>
28
+ </div>
29
  </div>
30
  <div id="gameOverScreen" class="absolute inset-0 hidden flex-col items-center justify-center bg-black bg-opacity-70 z-10">
31
  <h1 class="text-4xl md:text-5xl font-bold mb-4 text-red-400">Game Over</h1>
 
34
  <button id="restartBtn" class="px-8 py-3 bg-gradient-to-r from-purple-600 to-blue-600 rounded-full text-white font-bold text-lg hover:scale-105 transition-transform shadow-lg hover:shadow-purple-500/50">
35
  Try Again
36
  </button>
37
+ <p class="text-sm text-gray-300">Use arrow keys (←↑→↓) or swipe to move</p>
38
+ </div>
39
  </div>
40
  </div>
41
  <div class="mt-8 w-full max-w-4xl bg-black bg-opacity-30 rounded-2xl p-6 border border-purple-400 border-opacity-30">
script.js CHANGED
@@ -39,7 +39,7 @@ let rings = [];
39
  ball.x = canvas.width / 2;
40
  ball.y = canvas.height - 100;
41
  ball.dx = 0;
42
- ball.dy = -3; // Start moving upward when game begins
43
  rings = [];
44
  currentRing = 0;
45
 
@@ -218,6 +218,10 @@ rings = [];
218
  ball.dx = -ball.speed;
219
  } else if (e.key === 'ArrowRight') {
220
  ball.dx = ball.speed;
 
 
 
 
221
  }
222
  }
223
 
@@ -226,23 +230,28 @@ rings = [];
226
 
227
  if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
228
  ball.dx = 0;
 
 
229
  }
230
  }
231
-
232
- function handleTouchStart(e) {
233
  if (!gameActive) return;
234
  touchStartX = e.touches[0].clientX;
235
  touchStartY = e.touches[0].clientY;
236
  }
237
-
238
  function handleTouchMove(e) {
239
  if (!gameActive) return;
240
  e.preventDefault();
241
  const touchX = e.touches[0].clientX;
 
242
  const diffX = touchX - touchStartX;
 
243
 
244
  if (Math.abs(diffX) > 5) { // Threshold to prevent accidental movement
245
  ball.dx = diffX > 0 ? ball.speed : -ball.speed;
246
  }
 
 
 
247
  }
248
  });
 
39
  ball.x = canvas.width / 2;
40
  ball.y = canvas.height - 100;
41
  ball.dx = 0;
42
+ ball.dy = 0; // Start with no movement (let player control)
43
  rings = [];
44
  currentRing = 0;
45
 
 
218
  ball.dx = -ball.speed;
219
  } else if (e.key === 'ArrowRight') {
220
  ball.dx = ball.speed;
221
+ } else if (e.key === 'ArrowUp') {
222
+ ball.dy = -ball.speed;
223
+ } else if (e.key === 'ArrowDown') {
224
+ ball.dy = ball.speed;
225
  }
226
  }
227
 
 
230
 
231
  if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
232
  ball.dx = 0;
233
+ } else if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
234
+ ball.dy = 0;
235
  }
236
  }
237
+ function handleTouchStart(e) {
 
238
  if (!gameActive) return;
239
  touchStartX = e.touches[0].clientX;
240
  touchStartY = e.touches[0].clientY;
241
  }
 
242
  function handleTouchMove(e) {
243
  if (!gameActive) return;
244
  e.preventDefault();
245
  const touchX = e.touches[0].clientX;
246
+ const touchY = e.touches[0].clientY;
247
  const diffX = touchX - touchStartX;
248
+ const diffY = touchY - touchStartY;
249
 
250
  if (Math.abs(diffX) > 5) { // Threshold to prevent accidental movement
251
  ball.dx = diffX > 0 ? ball.speed : -ball.speed;
252
  }
253
+ if (Math.abs(diffY) > 5) {
254
+ ball.dy = diffY > 0 ? ball.speed : -ball.speed;
255
+ }
256
  }
257
  });