vikassabbi commited on
Commit
ff1f3ab
·
verified ·
1 Parent(s): 4a1548c

Add 2 files

Browse files
Files changed (2) hide show
  1. index.html +76 -12
  2. prompts.txt +1 -0
index.html CHANGED
@@ -232,6 +232,27 @@
232
  padding: 5px;
233
  border-radius: 3px;
234
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  </style>
236
  </head>
237
  <body>
@@ -244,6 +265,14 @@
244
  <div id="game-over">GAME OVER<br><span style="font-size: 24px;">Score: 0</span><br><button id="restart-button" style="margin-top: 20px; padding: 10px 20px; background: #f00; color: white; border: none; border-radius: 5px; cursor: pointer; pointer-events: auto;">PLAY AGAIN</button></div>
245
  <div class="powerup-indicator" id="powerup-indicator">DOUBLE FIRE ACTIVE!</div>
246
 
 
 
 
 
 
 
 
 
247
  <div id="mobile-controls">
248
  <div id="joystick">
249
  <div id="joystick-base">
@@ -260,8 +289,8 @@
260
  <div id="start-screen">
261
  <h1 class="title">GALACTIC DEFENDER</h1>
262
  <div class="instructions">
263
- <p><strong>CONTROLS:</strong> WASD to move, SPACE to fire, Q/E to roll, SHIFT to boost</p>
264
- <p><strong>MOUSE:</strong> Look around to change direction</p>
265
  <p><strong>POWER-UPS:</strong> Green = Health, Yellow = Double Fire</p>
266
  <p>Destroy alien ships before they reach you! Full 3D movement enabled.</p>
267
  </div>
@@ -281,8 +310,8 @@
281
 
282
  // Three.js variables
283
  let scene, camera, renderer;
284
- let player, playerSpeed = 0.5;
285
- let boostSpeed = 1.5;
286
  let currentSpeed = playerSpeed;
287
  let bullets = [];
288
  let enemies = [];
@@ -301,8 +330,8 @@
301
  let playerQuaternion = new THREE.Quaternion();
302
  let playerEuler = new THREE.Euler(0, 0, 0, 'YXZ');
303
  let playerVelocity = new THREE.Vector3();
304
- let playerRotationSpeed = 0.05;
305
- let playerRollSpeed = 0.03;
306
  let loader = new THREE.GLTFLoader();
307
 
308
  // Mobile controls
@@ -387,7 +416,11 @@
387
  // Start button event listener
388
  document.getElementById('start-button').addEventListener('click', startGame);
389
  document.getElementById('restart-button').addEventListener('click', restartGame);
390
- document.getElementById('fire-btn').addEventListener('touchstart', () => keys[' '] = true);
 
 
 
 
391
  document.getElementById('fire-btn').addEventListener('touchend', () => keys[' '] = false);
392
 
393
  // Start animation loop
@@ -401,6 +434,32 @@
401
  joystickBase.addEventListener('touchstart', handleJoystickStart, { passive: false });
402
  joystickBase.addEventListener('touchmove', handleJoystickMove, { passive: false });
403
  joystickBase.addEventListener('touchend', handleJoystickEnd, { passive: false });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  }
405
 
406
  function handleJoystickStart(e) {
@@ -435,14 +494,14 @@
435
  const posY = limitedDistance * Math.sin(angle);
436
  joystickHead.style.transform = `translate(${posX}px, ${posY}px)`;
437
 
438
- // Calculate movement direction
439
  movementX = dx / maxDistance;
440
- movementY = dy / maxDistance;
441
 
442
  // Normalize if outside circle
443
  if (distance > maxDistance) {
444
  movementX = dx / distance;
445
- movementY = dy / distance;
446
  }
447
  }
448
 
@@ -800,6 +859,11 @@
800
  debugMode = !debugMode;
801
  document.getElementById('debug-info').style.display = debugMode ? 'block' : 'none';
802
  }
 
 
 
 
 
803
  }
804
 
805
  function onKeyUp(event) {
@@ -870,7 +934,7 @@
870
  playerVelocity.add(right.multiplyScalar(moveX * currentSpeed * delta * 60));
871
  playerVelocity.add(forward.multiplyScalar(moveY * currentSpeed * delta * 60));
872
  } else {
873
- // Keyboard controls
874
  if (keys.w || keys.ArrowUp) playerVelocity.z -= currentSpeed * delta * 60;
875
  if (keys.s || keys.ArrowDown) playerVelocity.z += currentSpeed * delta * 60;
876
  if (keys.a || keys.ArrowLeft) playerVelocity.x -= currentSpeed * delta * 60;
@@ -890,7 +954,7 @@
890
  // Update player rotation based on direction
891
  player.quaternion.copy(playerQuaternion);
892
 
893
- // Shooting
894
  if (keys[' ']) {
895
  const now = Date.now();
896
  if (now - (player.lastShot || 0) > 300) { // Shoot every 300ms
 
232
  padding: 5px;
233
  border-radius: 3px;
234
  }
235
+ #desktop-controls {
236
+ position: absolute;
237
+ bottom: 20px;
238
+ left: 50%;
239
+ transform: translateX(-50%);
240
+ color: #aaa;
241
+ font-size: 14px;
242
+ text-align: center;
243
+ background: rgba(0,0,0,0.5);
244
+ padding: 10px 20px;
245
+ border-radius: 20px;
246
+ pointer-events: none;
247
+ }
248
+ .control-hint {
249
+ display: inline-block;
250
+ margin: 0 5px;
251
+ padding: 2px 8px;
252
+ background: rgba(255,255,255,0.1);
253
+ border-radius: 4px;
254
+ border: 1px solid #0ff;
255
+ }
256
  </style>
257
  </head>
258
  <body>
 
265
  <div id="game-over">GAME OVER<br><span style="font-size: 24px;">Score: 0</span><br><button id="restart-button" style="margin-top: 20px; padding: 10px 20px; background: #f00; color: white; border: none; border-radius: 5px; cursor: pointer; pointer-events: auto;">PLAY AGAIN</button></div>
266
  <div class="powerup-indicator" id="powerup-indicator">DOUBLE FIRE ACTIVE!</div>
267
 
268
+ <div id="desktop-controls">
269
+ <span class="control-hint">WASD</span> Move |
270
+ <span class="control-hint">Mouse</span> Aim |
271
+ <span class="control-hint">Space</span> Fire |
272
+ <span class="control-hint">Shift</span> Boost |
273
+ <span class="control-hint">Q/E</span> Roll
274
+ </div>
275
+
276
  <div id="mobile-controls">
277
  <div id="joystick">
278
  <div id="joystick-base">
 
289
  <div id="start-screen">
290
  <h1 class="title">GALACTIC DEFENDER</h1>
291
  <div class="instructions">
292
+ <p><strong>DESKTOP CONTROLS:</strong> WASD to move, Mouse to aim, SPACE to fire, SHIFT to boost, Q/E to roll</p>
293
+ <p><strong>MOBILE CONTROLS:</strong> Virtual joystick to move, FIRE button to shoot</p>
294
  <p><strong>POWER-UPS:</strong> Green = Health, Yellow = Double Fire</p>
295
  <p>Destroy alien ships before they reach you! Full 3D movement enabled.</p>
296
  </div>
 
310
 
311
  // Three.js variables
312
  let scene, camera, renderer;
313
+ let player, playerSpeed = 0.8; // Increased base speed
314
+ let boostSpeed = 2.0; // Increased boost speed
315
  let currentSpeed = playerSpeed;
316
  let bullets = [];
317
  let enemies = [];
 
330
  let playerQuaternion = new THREE.Quaternion();
331
  let playerEuler = new THREE.Euler(0, 0, 0, 'YXZ');
332
  let playerVelocity = new THREE.Vector3();
333
+ let playerRotationSpeed = 0.08; // Increased rotation speed
334
+ let playerRollSpeed = 0.05; // Increased roll speed
335
  let loader = new THREE.GLTFLoader();
336
 
337
  // Mobile controls
 
416
  // Start button event listener
417
  document.getElementById('start-button').addEventListener('click', startGame);
418
  document.getElementById('restart-button').addEventListener('click', restartGame);
419
+ document.getElementById('fire-btn').addEventListener('touchstart', () => {
420
+ keys[' '] = true;
421
+ // Auto-fire when holding the button
422
+ if (!gameOver) shoot();
423
+ });
424
  document.getElementById('fire-btn').addEventListener('touchend', () => keys[' '] = false);
425
 
426
  // Start animation loop
 
434
  joystickBase.addEventListener('touchstart', handleJoystickStart, { passive: false });
435
  joystickBase.addEventListener('touchmove', handleJoystickMove, { passive: false });
436
  joystickBase.addEventListener('touchend', handleJoystickEnd, { passive: false });
437
+
438
+ // Add touch event for the whole screen to control aiming
439
+ renderer.domElement.addEventListener('touchmove', handleTouchAim, { passive: false });
440
+ }
441
+
442
+ function handleTouchAim(e) {
443
+ if (gameOver || !joystickActive) return;
444
+ e.preventDefault();
445
+
446
+ const touch = e.touches[0];
447
+ const centerX = window.innerWidth / 2;
448
+ const centerY = window.innerHeight / 2;
449
+
450
+ // Calculate relative movement from center
451
+ const movementX = (touch.clientX - centerX) / 100;
452
+ const movementY = (touch.clientY - centerY) / 100;
453
+
454
+ // Update player direction based on touch position
455
+ playerEuler.y -= movementX * 0.002;
456
+ playerEuler.x -= movementY * 0.002;
457
+
458
+ // Limit vertical rotation to prevent flipping
459
+ playerEuler.x = Math.max(-Math.PI / 2, Math.min(Math.PI / 2, playerEuler.x));
460
+
461
+ playerQuaternion.setFromEuler(playerEuler);
462
+ playerDirection.set(0, 0, -1).applyQuaternion(playerQuaternion);
463
  }
464
 
465
  function handleJoystickStart(e) {
 
494
  const posY = limitedDistance * Math.sin(angle);
495
  joystickHead.style.transform = `translate(${posX}px, ${posY}px)`;
496
 
497
+ // Calculate movement direction (invert Y for natural movement)
498
  movementX = dx / maxDistance;
499
+ movementY = -dy / maxDistance; // Inverted Y axis
500
 
501
  // Normalize if outside circle
502
  if (distance > maxDistance) {
503
  movementX = dx / distance;
504
+ movementY = -dy / distance; // Inverted Y axis
505
  }
506
  }
507
 
 
859
  debugMode = !debugMode;
860
  document.getElementById('debug-info').style.display = debugMode ? 'block' : 'none';
861
  }
862
+
863
+ // Auto-fire when space is held down
864
+ if (event.key === ' ' && !gameOver) {
865
+ shoot();
866
+ }
867
  }
868
 
869
  function onKeyUp(event) {
 
934
  playerVelocity.add(right.multiplyScalar(moveX * currentSpeed * delta * 60));
935
  playerVelocity.add(forward.multiplyScalar(moveY * currentSpeed * delta * 60));
936
  } else {
937
+ // Keyboard controls (now more responsive)
938
  if (keys.w || keys.ArrowUp) playerVelocity.z -= currentSpeed * delta * 60;
939
  if (keys.s || keys.ArrowDown) playerVelocity.z += currentSpeed * delta * 60;
940
  if (keys.a || keys.ArrowLeft) playerVelocity.x -= currentSpeed * delta * 60;
 
954
  // Update player rotation based on direction
955
  player.quaternion.copy(playerQuaternion);
956
 
957
+ // Auto-fire when space is held down
958
  if (keys[' ']) {
959
  const now = Date.now();
960
  if (now - (player.lastShot || 0) > 300) { // Shoot every 300ms
prompts.txt CHANGED
@@ -0,0 +1 @@
 
 
1
+ the controls are not that good, can you fix that?