Spaces:
Running
Running
cutechicken
commited on
Commit
β’
75e71ec
1
Parent(s):
b96edd4
Update game.js
Browse files
game.js
CHANGED
@@ -75,34 +75,36 @@ class TankPlayer {
|
|
75 |
}
|
76 |
|
77 |
shoot(scene) {
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
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;
|