cutechicken commited on
Commit
75e71ec
β€’
1 Parent(s): b96edd4

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +30 -28
game.js CHANGED
@@ -75,34 +75,36 @@ class TankPlayer {
75
  }
76
 
77
  shoot(scene) {
78
- const currentTime = Date.now();
79
- if (currentTime - this.lastShootTime < this.shootInterval || this.ammo <= 0) return null;
80
-
81
- // μ΄μ•Œ 생성
82
- const bulletGeometry = new THREE.SphereGeometry(0.2);
83
- const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
84
- const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
85
-
86
- // μ΄μ•Œ μ‹œμž‘ μœ„μΉ˜ (포탑 끝)
87
- const bulletOffset = new THREE.Vector3(0, 0.5, 2);
88
- bulletOffset.applyQuaternion(this.turret.quaternion);
89
- bullet.position.copy(this.body.position).add(bulletOffset);
90
-
91
- // μ΄μ•Œ 속도 (카메라/포탑 λ°©ν–₯)
92
- const direction = new THREE.Vector3(0, 0, 1);
93
- direction.applyQuaternion(this.turret.quaternion);
94
- bullet.velocity = direction.multiplyScalar(2);
95
-
96
- scene.add(bullet);
97
- this.bullets.push(bullet);
98
- this.ammo--;
99
- this.lastShootTime = currentTime;
100
-
101
- // UI μ—…λ°μ΄νŠΈ
102
- document.getElementById('ammo').textContent = `Ammo: ${this.ammo}/10`;
103
-
104
- return bullet;
105
- }
 
 
106
 
107
  update(mouseX, mouseY) {
108
  if (!this.body || !this.turretGroup) return;
 
75
  }
76
 
77
  shoot(scene) {
78
+ const currentTime = Date.now();
79
+ if (currentTime - this.lastShootTime < this.shootInterval || this.ammo <= 0) return null;
80
+
81
+ // μ΄μ•Œ 생성
82
+ const bulletGeometry = new THREE.SphereGeometry(0.2);
83
+ const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
84
+ const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
85
+
86
+ // μ΄μ•Œ μ‹œμž‘ μœ„μΉ˜ (포탑 끝)
87
+ const bulletOffset = new THREE.Vector3(0, 0.5, 2);
88
+ // ν¬νƒ‘μ˜ νšŒμ „μ„ 적용
89
+ bulletOffset.applyQuaternion(this.turretGroup.quaternion);
90
+ bulletOffset.applyQuaternion(this.body.quaternion);
91
+ bullet.position.copy(this.body.position).add(bulletOffset);
92
+
93
+ // μ΄μ•Œ 속도 (포탑 λ°©ν–₯)
94
+ const direction = new THREE.Vector3(0, 0, 1);
95
+ direction.applyQuaternion(this.turretGroup.quaternion);
96
+ direction.applyQuaternion(this.body.quaternion);
97
+ bullet.velocity = direction.multiplyScalar(2);
98
+
99
+ scene.add(bullet);
100
+ this.bullets.push(bullet);
101
+ this.ammo--;
102
+ this.lastShootTime = currentTime;
103
+
104
+ document.getElementById('ammo').textContent = `Ammo: ${this.ammo}/10`;
105
+
106
+ return bullet;
107
+ }
108
 
109
  update(mouseX, mouseY) {
110
  if (!this.body || !this.turretGroup) return;