cutechicken commited on
Commit
ad7f1aa
ยท
verified ยท
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