cutechicken commited on
Commit
ad7f1aa
β€’
1 Parent(s): 4f3870f

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +33 -4
game.js CHANGED
@@ -127,16 +127,26 @@ class TankPlayer {
127
  }
128
 
129
  shoot(scene) {
130
- if (this.isReloading || this.ammo <= 0) return null;
 
 
 
 
 
 
 
 
 
 
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
- this.startReload();
 
 
 
 
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