Spaces:
Running
Running
cutechicken
commited on
Commit
โข
2ecc8f4
1
Parent(s):
df489df
Update game.js
Browse files
game.js
CHANGED
@@ -75,32 +75,91 @@ 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 |
update(mouseX, mouseY, scene) {
|
106 |
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) {
|
80 |
+
if (this.ammo === 0) {
|
81 |
+
console.log('Out of ammo! Reload required.');
|
82 |
+
}
|
83 |
+
return null;
|
84 |
+
}
|
85 |
|
86 |
+
const bulletGeometry = new THREE.SphereGeometry(0.2);
|
87 |
+
const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
|
88 |
+
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
89 |
|
90 |
+
const bulletOffset = new THREE.Vector3(0, 0.5, 2);
|
91 |
+
bulletOffset.applyQuaternion(this.turretGroup.quaternion);
|
92 |
+
bulletOffset.applyQuaternion(this.body.quaternion);
|
93 |
+
bullet.position.copy(this.body.position).add(bulletOffset);
|
94 |
|
95 |
+
const direction = new THREE.Vector3(0, 0, 1);
|
96 |
+
direction.applyQuaternion(this.turretGroup.quaternion);
|
97 |
+
direction.applyQuaternion(this.body.quaternion);
|
98 |
+
bullet.velocity = direction.multiplyScalar(2);
|
99 |
|
100 |
+
scene.add(bullet);
|
101 |
+
this.bullets.push(bullet);
|
102 |
+
this.ammo--;
|
103 |
+
this.lastShootTime = currentTime;
|
104 |
|
105 |
+
// UI ์
๋ฐ์ดํธ
|
106 |
+
document.getElementById('ammo').textContent = `${this.ammo}/10`;
|
107 |
+
|
108 |
+
// ์ฐ๊ธฐ ํจ๊ณผ ์์ฑ
|
109 |
+
this.createSmokeEffect(scene, bulletOffset);
|
110 |
+
|
111 |
+
// ๋ฐ์ฌ ์๋ฆฌ ์ฌ์
|
112 |
+
this.playRandomFireSound();
|
113 |
+
|
114 |
+
return bullet;
|
115 |
+
}
|
116 |
+
|
117 |
+
// ์ฐ๊ธฐ ํจ๊ณผ ์์ฑ ๋ฉ์๋
|
118 |
+
createSmokeEffect(scene, position) {
|
119 |
+
const particleCount = 10;
|
120 |
+
for (let i = 0; i < particleCount; i++) {
|
121 |
+
const smokeGeometry = new THREE.SphereGeometry(0.1, 8, 8);
|
122 |
+
const smokeMaterial = new THREE.MeshBasicMaterial({ color: 0x555555, transparent: true, opacity: 0.5 });
|
123 |
+
const smoke = new THREE.Mesh(smokeGeometry, smokeMaterial);
|
124 |
+
smoke.position.copy(this.body.position.clone().add(position));
|
125 |
+
smoke.velocity = new THREE.Vector3(
|
126 |
+
(Math.random() - 0.5) * 0.5,
|
127 |
+
Math.random() * 0.2,
|
128 |
+
(Math.random() - 0.5) * 0.5
|
129 |
+
);
|
130 |
+
smoke.lifetime = 50;
|
131 |
+
|
132 |
+
scene.add(smoke);
|
133 |
+
|
134 |
+
// ์ฐ๊ธฐ ์
๋ฐ์ดํธ ๋ก์ง
|
135 |
+
const updateSmoke = () => {
|
136 |
+
if (smoke.lifetime <= 0) {
|
137 |
+
scene.remove(smoke);
|
138 |
+
return;
|
139 |
+
}
|
140 |
+
smoke.lifetime--;
|
141 |
+
smoke.position.add(smoke.velocity);
|
142 |
+
smoke.material.opacity -= 0.01;
|
143 |
+
requestAnimationFrame(updateSmoke);
|
144 |
+
};
|
145 |
+
updateSmoke();
|
146 |
}
|
147 |
+
}
|
148 |
+
|
149 |
+
// ๋ฌด์์ ๋ฐ์ฌ ์๋ฆฌ ์ฌ์ ๋ฉ์๋
|
150 |
+
playRandomFireSound() {
|
151 |
+
const sounds = [
|
152 |
+
"sounds/mbtfire1.ogg",
|
153 |
+
"sounds/mbtfire2.ogg",
|
154 |
+
"sounds/mbtfire3.ogg",
|
155 |
+
"sounds/mbtfire4.ogg",
|
156 |
+
"sounds/mbtfire5.ogg"
|
157 |
+
];
|
158 |
+
const randomSound = sounds[Math.floor(Math.random() * sounds.length)];
|
159 |
+
const audio = new Audio(randomSound);
|
160 |
+
audio.play();
|
161 |
+
}
|
162 |
+
|
163 |
|
164 |
update(mouseX, mouseY, scene) {
|
165 |
if (!this.body || !this.turretGroup) return;
|