cutechicken commited on
Commit
590c2f2
β€’
1 Parent(s): ad7f1aa

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +10 -1
game.js CHANGED
@@ -139,11 +139,19 @@ class TankPlayer {
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
  // λ°œμ‚¬ μ΄νŽ™νŠΈ
@@ -638,6 +646,7 @@ class Game {
638
  this.lastTime = performance.now();
639
  this.gameTimer = null;
640
  this.animationFrameId = null;
 
641
 
642
  this.mouse = { x: 0, y: 0 };
643
  this.keys = {
 
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
+
148
+ // 이전 μ˜€λ””μ˜€ μΈμŠ€ν„΄μŠ€κ°€ μžˆλ‹€λ©΄ 쀑지
149
+ if (this.lastAudio) {
150
+ this.lastAudio.pause();
151
+ this.lastAudio.currentTime = 0;
152
+ }
153
+
154
+ this.lastAudio = audio;
155
  audio.play();
156
 
157
  // λ°œμ‚¬ μ΄νŽ™νŠΈ
 
646
  this.lastTime = performance.now();
647
  this.gameTimer = null;
648
  this.animationFrameId = null;
649
+ this.lastAudio = null; // λ§ˆμ§€λ§‰ λ°œμ‚¬μŒ 좔적을 μœ„ν•œ 속성 μΆ”κ°€
650
 
651
  this.mouse = { x: 0, y: 0 };
652
  this.keys = {