cutechicken commited on
Commit
ebc3901
ยท
verified ยท
1 Parent(s): 1bd8588

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +26 -18
game.js CHANGED
@@ -105,10 +105,13 @@ class TankPlayer {
105
  update(mouseX, mouseY, scene) {
106
  if (!this.body || !this.turretGroup) return;
107
 
108
- // ํฌํƒ‘ ํšŒ์ „ - ๋งˆ์šฐ์Šค ์ด๋™์— ๋”ฐ๋ผ ์ž์œ ๋กญ๊ฒŒ 360๋„ ํšŒ์ „
109
- this.turretGroup.rotation.y += mouseX * 0.03;
 
 
 
110
 
111
- // ํ”Œ๋ ˆ์ด์–ด ์ด์•Œ ์ด๋™ ์ฒ˜๋ฆฌ
112
  for (let i = this.bullets.length - 1; i >= 0; i--) {
113
  const bullet = this.bullets[i];
114
  bullet.position.add(bullet.velocity);
@@ -481,9 +484,14 @@ async addDesertDecorations() {
481
  document.addEventListener('mousemove', (event) => {
482
  if (this.isLoading || this.isGameOver || !document.pointerLockElement) return;
483
 
484
- // ์ปค์„œ ์ด๋™์— ๋”ฐ๋ผ ๊ฐ’ ์—…๋ฐ์ดํŠธ (ํšŒ์ „ ๊ฐ๋„๋ฅผ ์ œํ•œ)
485
- this.mouse.x = Math.max(Math.min(this.mouse.x + event.movementX * 0.002, 1), -1);
486
- this.mouse.y = Math.max(Math.min(this.mouse.y + event.movementY * 0.002, 1), -1);
 
 
 
 
 
487
  });
488
 
489
 
@@ -532,26 +540,26 @@ async addDesertDecorations() {
532
  this.tank.move(direction);
533
  }
534
 
535
- // ์นด๋ฉ”๋ผ ์œ„์น˜ ์—…๋ฐ์ดํŠธ - ํฌํƒ‘ ํšŒ์ „๋งŒ ๋”ฐ๋ผ๊ฐ€๋„๋ก ์ˆ˜์ •
536
  const tankPos = this.tank.getPosition();
537
- const turretRotation = this.tank.turretGroup.rotation.y;
538
  const cameraDistance = 30;
539
  const cameraHeight = 15;
540
 
541
- // ์นด๋ฉ”๋ผ ์œ„์น˜๋ฅผ ํฌํƒ‘ ํšŒ์ „์— ๋งž์ถฐ ์„ค์ •
542
  this.camera.position.set(
543
- tankPos.x - Math.sin(turretRotation) * cameraDistance,
544
  tankPos.y + cameraHeight,
545
- tankPos.z - Math.cos(turretRotation) * cameraDistance
546
- );
547
-
548
- // ์นด๋ฉ”๋ผ๊ฐ€ ํ•ญ์ƒ ํฌํƒ‘์„ ๋ฐ”๋ผ๋ณด๋„๋ก ์„ค์ •
549
- const lookAtPoint = new THREE.Vector3(
550
- tankPos.x + Math.sin(turretRotation) * 10,
551
- tankPos.y + 5,
552
- tankPos.z + Math.cos(turretRotation) * 10
553
  );
554
 
 
 
 
 
 
 
 
555
  this.camera.lookAt(lookAtPoint);
556
  }
557
 
 
105
  update(mouseX, mouseY, scene) {
106
  if (!this.body || !this.turretGroup) return;
107
 
108
+ // ํฌํƒ‘ ํšŒ์ „ - ๋งˆ์šฐ์Šค ์œ„์น˜์— ๋”ฐ๋ผ ํšŒ์ „
109
+ const screenCenter = new THREE.Vector2(0, 0);
110
+ const mousePosition = new THREE.Vector2(mouseX, mouseY);
111
+ const angle = Math.atan2(mousePosition.x - screenCenter.x, mousePosition.y - screenCenter.y);
112
+ this.turretGroup.rotation.y = angle;
113
 
114
+ // ํ”Œ๋ ˆ์ด์–ด ์ด์•Œ ์—…๋ฐ์ดํŠธ
115
  for (let i = this.bullets.length - 1; i >= 0; i--) {
116
  const bullet = this.bullets[i];
117
  bullet.position.add(bullet.velocity);
 
484
  document.addEventListener('mousemove', (event) => {
485
  if (this.isLoading || this.isGameOver || !document.pointerLockElement) return;
486
 
487
+ // ๋งˆ์šฐ์Šค ์›€์ง์ž„์„ ํ™”๋ฉด ์ค‘์•™ ๊ธฐ์ค€์œผ๋กœ ์ •๊ทœํ™”
488
+ const movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
489
+ const movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
490
+
491
+ this.mouse.x += movementX * 0.002;
492
+ this.mouse.y += movementY * 0.002;
493
+
494
+ // ๋งˆ์šฐ์Šค ์ด๋™
495
  });
496
 
497
 
 
540
  this.tank.move(direction);
541
  }
542
 
543
+ // ์นด๋ฉ”๋ผ ์œ„์น˜ ์—…๋ฐ์ดํŠธ - ํ•ญ์ƒ ํƒฑํฌ ๋’ค์—์„œ ๋ฐ”๋ผ๋ณด๋„๋ก ์„ค์ •
544
  const tankPos = this.tank.getPosition();
545
+ const tankRotation = this.tank.body.rotation.y;
546
  const cameraDistance = 30;
547
  const cameraHeight = 15;
548
 
549
+ // ํƒฑํฌ์˜ ๋’ค์ชฝ ์œ„์น˜์— ์นด๋ฉ”๋ผ ๋ฐฐ์น˜
550
  this.camera.position.set(
551
+ tankPos.x - Math.sin(tankRotation) * cameraDistance,
552
  tankPos.y + cameraHeight,
553
+ tankPos.z - Math.cos(tankRotation) * cameraDistance
 
 
 
 
 
 
 
554
  );
555
 
556
+ // ์นด๋ฉ”๋ผ๊ฐ€ ํ•ญ์ƒ ํƒฑํฌ๋ฅผ ๋ฐ”๋ผ๋ณด๋„๋ก ์„ค์ •
557
+ this.camera.lookAt(new THREE.Vector3(
558
+ tankPos.x,
559
+ tankPos.y,
560
+ tankPos.z
561
+ ));
562
+ //}
563
  this.camera.lookAt(lookAtPoint);
564
  }
565