cutechicken commited on
Commit
dbfb9bd
โ€ข
1 Parent(s): e239318

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +50 -50
game.js CHANGED
@@ -105,6 +105,12 @@ class TankPlayer {
105
  update(mouseX, mouseY, scene) {
106
  if (!this.body || !this.turretGroup) return;
107
 
 
 
 
 
 
 
108
  for (let i = this.bullets.length - 1; i >= 0; i--) {
109
  const bullet = this.bullets[i];
110
  bullet.position.add(bullet.velocity);
@@ -115,13 +121,6 @@ class TankPlayer {
115
  this.bullets.splice(i, 1);
116
  }
117
  }
118
-
119
- // ํฌํƒ‘ ํšŒ์ „ ๋ฐฉํ–ฅ ์ˆ˜์ •
120
- if (this.turretGroup) {
121
- const rotationAngle = -Math.atan2(mouseX, mouseY); // ๋ถ€ํ˜ธ๋ฅผ ๋ฐ˜๋Œ€๋กœ ํ•˜์—ฌ ํšŒ์ „ ๋ฐฉํ–ฅ ๋ณ€๊ฒฝ
122
- this.turretRotation = rotationAngle;
123
- this.turretGroup.rotation.y = this.turretRotation;
124
- }
125
  }
126
 
127
  move(direction) {
@@ -510,53 +509,54 @@ async addDesertDecorations() {
510
  }
511
 
512
  handleMovement() {
513
- if (!this.tank.isLoaded || this.isGameOver) return;
514
-
515
- const direction = new THREE.Vector3();
516
-
517
- if (this.keys.forward) direction.z += 1;
518
- if (this.keys.backward) direction.z -= 1;
519
- if (this.keys.left) direction.x -= 1;
520
- if (this.keys.right) direction.x += 1;
521
-
522
- if (direction.length() > 0) {
523
- direction.normalize();
524
 
525
- if (this.keys.left) this.tank.rotate(-1);
526
- if (this.keys.right) this.tank.rotate(1);
527
 
528
- direction.applyEuler(this.tank.body.rotation);
529
- this.tank.move(direction);
530
- }
 
 
 
 
 
 
 
 
 
 
 
531
 
532
- // ํฌํƒ‘ ํšŒ์ „ ์—…๋ฐ์ดํŠธ
533
- const mouseVector = new THREE.Vector2(this.mouse.x, -this.mouse.y);
534
- const rotationAngle = -Math.atan2(mouseVector.x, mouseVector.y); // ๋ถ€ํ˜ธ ๋ณ€๊ฒฝ
535
-
536
- if (this.tank.turretGroup) {
537
- this.tank.turretGroup.rotation.y = rotationAngle;
538
- }
 
539
 
540
- // ์นด๋ฉ”๋ผ ์œ„์น˜ ์—…๋ฐ์ดํŠธ
541
- const tankPos = this.tank.getPosition();
542
- const cameraDistance = 30;
543
- const cameraHeight = 15;
544
- const lookAtHeight = 5;
545
-
546
- const turretRotation = this.tank.turretGroup.rotation.y + this.tank.body.rotation.y;
547
- this.camera.position.set(
548
- tankPos.x - Math.sin(turretRotation) * cameraDistance,
549
- tankPos.y + cameraHeight,
550
- tankPos.z - Math.cos(turretRotation) * cameraDistance
551
- );
552
-
553
- const lookAtPoint = new THREE.Vector3(
554
- tankPos.x + Math.sin(turretRotation) * 10,
555
- tankPos.y + lookAtHeight,
556
- tankPos.z + Math.cos(turretRotation) * 10
557
- );
558
-
559
- this.camera.lookAt(lookAtPoint);
560
  }
561
 
562
  createBuildings() {
 
105
  update(mouseX, mouseY, scene) {
106
  if (!this.body || !this.turretGroup) return;
107
 
108
+ // ํฌํƒ‘ ํšŒ์ „ ๊ณ„์‚ฐ ์ˆ˜์ •
109
+ const rotationAngle = Math.atan2(mouseX, mouseY);
110
+ this.turretRotation = rotationAngle;
111
+ this.turretGroup.rotation.y = this.turretRotation;
112
+
113
+ // ์ด์•Œ ์—…๋ฐ์ดํŠธ ๋กœ์ง
114
  for (let i = this.bullets.length - 1; i >= 0; i--) {
115
  const bullet = this.bullets[i];
116
  bullet.position.add(bullet.velocity);
 
121
  this.bullets.splice(i, 1);
122
  }
123
  }
 
 
 
 
 
 
 
124
  }
125
 
126
  move(direction) {
 
509
  }
510
 
511
  handleMovement() {
512
+ if (!this.tank.isLoaded || this.isGameOver) return;
 
 
 
 
 
 
 
 
 
 
513
 
514
+ const direction = new THREE.Vector3();
 
515
 
516
+ if (this.keys.forward) direction.z += 1;
517
+ if (this.keys.backward) direction.z -= 1;
518
+ if (this.keys.left) direction.x -= 1;
519
+ if (this.keys.right) direction.x += 1;
520
+
521
+ if (direction.length() > 0) {
522
+ direction.normalize();
523
+
524
+ if (this.keys.left) this.tank.rotate(-1);
525
+ if (this.keys.right) this.tank.rotate(1);
526
+
527
+ direction.applyEuler(this.tank.body.rotation);
528
+ this.tank.move(direction);
529
+ }
530
 
531
+ // ๋งˆ์šฐ์Šค ์›€์ง์ž„์— ๋”ฐ๋ฅธ ํฌํƒ‘ ํšŒ์ „ ์ฒ˜๋ฆฌ
532
+ const tankRotation = this.tank.body.rotation.y;
533
+ const mouseAngle = Math.atan2(this.mouse.x, -this.mouse.y);
534
+ const finalRotation = mouseAngle + tankRotation;
535
+
536
+ if (this.tank.turretGroup) {
537
+ this.tank.turretGroup.rotation.y = finalRotation;
538
+ }
539
 
540
+ // ์นด๋ฉ”๋ผ ์œ„์น˜ ์—…๋ฐ์ดํŠธ
541
+ const tankPos = this.tank.getPosition();
542
+ const cameraDistance = 30;
543
+ const cameraHeight = 15;
544
+ const lookAtHeight = 5;
545
+
546
+ this.camera.position.set(
547
+ tankPos.x - Math.sin(finalRotation) * cameraDistance,
548
+ tankPos.y + cameraHeight,
549
+ tankPos.z - Math.cos(finalRotation) * cameraDistance
550
+ );
551
+
552
+ const lookAtPoint = new THREE.Vector3(
553
+ tankPos.x + Math.sin(finalRotation) * 10,
554
+ tankPos.y + lookAtHeight,
555
+ tankPos.z + Math.cos(finalRotation) * 10
556
+ );
557
+
558
+ this.camera.lookAt(lookAtPoint);
559
+ }
560
  }
561
 
562
  createBuildings() {