Update game.js
Browse files
game.js
CHANGED
|
@@ -136,6 +136,10 @@ class TankPlayer {
|
|
| 136 |
audio.volume = 0.5;
|
| 137 |
audio.play();
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
const bullet = this.createBullet(scene);
|
| 140 |
if (bullet) {
|
| 141 |
this.ammo--;
|
|
@@ -145,27 +149,76 @@ class TankPlayer {
|
|
| 145 |
return bullet;
|
| 146 |
}
|
| 147 |
|
| 148 |
-
|
| 149 |
-
const
|
| 150 |
-
const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
|
| 151 |
-
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
| 152 |
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
| 167 |
}
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
update(mouseX, mouseY, scene) {
|
| 170 |
if (!this.body || !this.turretGroup) return;
|
| 171 |
|
|
|
|
| 136 |
audio.volume = 0.5;
|
| 137 |
audio.play();
|
| 138 |
|
| 139 |
+
// ๋ฐ์ฌ ์ดํํธ ์ถ๊ฐ
|
| 140 |
+
this.createMuzzleFlash(scene);
|
| 141 |
+
|
| 142 |
+
// ํฌํ ์์ฑ
|
| 143 |
const bullet = this.createBullet(scene);
|
| 144 |
if (bullet) {
|
| 145 |
this.ammo--;
|
|
|
|
| 149 |
return bullet;
|
| 150 |
}
|
| 151 |
|
| 152 |
+
createMuzzleFlash(scene) {
|
| 153 |
+
const flashGroup = new THREE.Group();
|
|
|
|
|
|
|
| 154 |
|
| 155 |
+
// ํ์ผ ์์ฑ
|
| 156 |
+
const flameGeometry = new THREE.SphereGeometry(0.5, 8, 8);
|
| 157 |
+
const flameMaterial = new THREE.MeshBasicMaterial({
|
| 158 |
+
color: 0xffa500,
|
| 159 |
+
transparent: true,
|
| 160 |
+
opacity: 0.8
|
| 161 |
+
});
|
| 162 |
+
const flame = new THREE.Mesh(flameGeometry, flameMaterial);
|
| 163 |
+
flame.scale.set(1.5, 1.5, 2);
|
| 164 |
+
flashGroup.add(flame);
|
| 165 |
+
|
| 166 |
+
// ์ฐ๊ธฐ ์์ฑ
|
| 167 |
+
const smokeGeometry = new THREE.SphereGeometry(0.3, 8, 8);
|
| 168 |
+
const smokeMaterial = new THREE.MeshBasicMaterial({
|
| 169 |
+
color: 0x555555,
|
| 170 |
+
transparent: true,
|
| 171 |
+
opacity: 0.5
|
| 172 |
+
});
|
| 173 |
+
for (let i = 0; i < 3; i++) {
|
| 174 |
+
const smoke = new THREE.Mesh(smokeGeometry, smokeMaterial);
|
| 175 |
+
smoke.position.set(
|
| 176 |
+
Math.random() * 0.5 - 0.25,
|
| 177 |
+
Math.random() * 0.5 - 0.25,
|
| 178 |
+
-0.5 - Math.random() * 0.5
|
| 179 |
+
);
|
| 180 |
+
flashGroup.add(smoke);
|
| 181 |
+
}
|
| 182 |
|
| 183 |
+
// ์์น ์ค์ (ํฌํ ๋)
|
| 184 |
+
const muzzlePosition = new THREE.Vector3(0, 0.5, 2);
|
| 185 |
+
muzzlePosition.applyQuaternion(this.turretGroup.quaternion);
|
| 186 |
+
muzzlePosition.applyQuaternion(this.body.quaternion);
|
| 187 |
+
flashGroup.position.copy(this.body.position).add(muzzlePosition);
|
| 188 |
|
| 189 |
+
// ์ฌ์ ์ถ๊ฐ
|
| 190 |
+
scene.add(flashGroup);
|
| 191 |
|
| 192 |
+
// ์ผ์ ์๊ฐ ํ ์ ๊ฑฐ
|
| 193 |
+
setTimeout(() => {
|
| 194 |
+
scene.remove(flashGroup);
|
| 195 |
+
}, 300); // 300ms ์ ์ง
|
| 196 |
}
|
| 197 |
|
| 198 |
+
|
| 199 |
+
createBullet(scene) {
|
| 200 |
+
const bulletGeometry = new THREE.CylinderGeometry(0.1, 0.1, 1, 8);
|
| 201 |
+
const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0xffd700 });
|
| 202 |
+
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
| 203 |
+
|
| 204 |
+
bullet.rotation.x = Math.PI / 2; // ์ํ์ผ๋ก ํ์
|
| 205 |
+
const bulletOffset = new THREE.Vector3(0, 0.5, 2);
|
| 206 |
+
bulletOffset.applyQuaternion(this.turretGroup.quaternion);
|
| 207 |
+
bulletOffset.applyQuaternion(this.body.quaternion);
|
| 208 |
+
bullet.position.copy(this.body.position).add(bulletOffset);
|
| 209 |
+
|
| 210 |
+
const direction = new THREE.Vector3(0, 0, 1);
|
| 211 |
+
direction.applyQuaternion(this.turretGroup.quaternion);
|
| 212 |
+
direction.applyQuaternion(this.body.quaternion);
|
| 213 |
+
bullet.velocity = direction.multiplyScalar(5);
|
| 214 |
+
|
| 215 |
+
scene.add(bullet);
|
| 216 |
+
this.bullets.push(bullet);
|
| 217 |
+
|
| 218 |
+
return bullet;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
|
| 222 |
update(mouseX, mouseY, scene) {
|
| 223 |
if (!this.body || !this.turretGroup) return;
|
| 224 |
|