Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
|
@@ -127,16 +127,26 @@ class TankPlayer {
|
|
| 127 |
}
|
| 128 |
|
| 129 |
shoot(scene) {
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
-
// λ°μ¬μ ν¨κ³Ό
|
| 133 |
const sounds = ['sounds/mbtfire1.ogg', 'sounds/mbtfire2.ogg', 'sounds/mbtfire3.ogg', 'sounds/mbtfire4.ogg'];
|
| 134 |
const randomSound = sounds[Math.floor(Math.random() * sounds.length)];
|
| 135 |
const audio = new Audio(randomSound);
|
| 136 |
audio.volume = 0.5;
|
| 137 |
audio.play();
|
| 138 |
|
| 139 |
-
// λ°μ¬ μ΄ννΈ
|
| 140 |
this.createMuzzleFlash(scene);
|
| 141 |
|
| 142 |
// ν¬ν μμ±
|
|
@@ -144,11 +154,30 @@ class TankPlayer {
|
|
| 144 |
if (bullet) {
|
| 145 |
this.ammo--;
|
| 146 |
this.updateAmmoDisplay();
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
}
|
| 149 |
return bullet;
|
| 150 |
}
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
createMuzzleFlash(scene) {
|
| 153 |
const flashGroup = new THREE.Group();
|
| 154 |
|
|
|
|
| 127 |
}
|
| 128 |
|
| 129 |
shoot(scene) {
|
| 130 |
+
// μ¬μ₯μ μ€μ΄κ±°λ νμ½μ΄ μμΌλ©΄ λ°μ¬νμ§ μμ
|
| 131 |
+
if (this.isReloading || this.ammo <= 0) {
|
| 132 |
+
return null;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
// λ°μ¬ λλ μ΄ μ²΄ν¬ (μ°μ λ°μ¬ λ°©μ§)
|
| 136 |
+
const currentTime = Date.now();
|
| 137 |
+
if (currentTime - this.lastShootTime < 100) { // 100msμ λ°μ¬ λλ μ΄
|
| 138 |
+
return null;
|
| 139 |
+
}
|
| 140 |
+
this.lastShootTime = currentTime;
|
| 141 |
|
| 142 |
+
// λ°μ¬μ ν¨κ³Ό
|
| 143 |
const sounds = ['sounds/mbtfire1.ogg', 'sounds/mbtfire2.ogg', 'sounds/mbtfire3.ogg', 'sounds/mbtfire4.ogg'];
|
| 144 |
const randomSound = sounds[Math.floor(Math.random() * sounds.length)];
|
| 145 |
const audio = new Audio(randomSound);
|
| 146 |
audio.volume = 0.5;
|
| 147 |
audio.play();
|
| 148 |
|
| 149 |
+
// λ°μ¬ μ΄ννΈ
|
| 150 |
this.createMuzzleFlash(scene);
|
| 151 |
|
| 152 |
// ν¬ν μμ±
|
|
|
|
| 154 |
if (bullet) {
|
| 155 |
this.ammo--;
|
| 156 |
this.updateAmmoDisplay();
|
| 157 |
+
|
| 158 |
+
// νμ½μ λͺ¨λ μμ§νμ λλ§ μ¬μ₯μ μμ
|
| 159 |
+
if (this.ammo <= 0) {
|
| 160 |
+
this.startReload();
|
| 161 |
+
}
|
| 162 |
}
|
| 163 |
return bullet;
|
| 164 |
}
|
| 165 |
|
| 166 |
+
startReload() {
|
| 167 |
+
if (this.isReloading) return; // μ΄λ―Έ μ¬μ₯μ μ€μ΄λ©΄ 무μ
|
| 168 |
+
|
| 169 |
+
this.isReloading = true;
|
| 170 |
+
const reloadingText = document.getElementById('reloadingText');
|
| 171 |
+
reloadingText.style.display = 'block';
|
| 172 |
+
|
| 173 |
+
setTimeout(() => {
|
| 174 |
+
this.ammo = this.maxAmmo;
|
| 175 |
+
this.isReloading = false;
|
| 176 |
+
reloadingText.style.display = 'none';
|
| 177 |
+
this.updateAmmoDisplay();
|
| 178 |
+
}, this.reloadTime);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
createMuzzleFlash(scene) {
|
| 182 |
const flashGroup = new THREE.Group();
|
| 183 |
|