cutechicken commited on
Commit
ea69448
β€’
1 Parent(s): 27969e9

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +16 -5
game.js CHANGED
@@ -850,6 +850,8 @@ class Game {
850
  // κ²Œμž„ μ‹œμž‘ μ—¬λΆ€λ₯Ό μΆ”μ ν•˜λŠ” ν”Œλž˜κ·Έ μΆ”κ°€
851
  this.isStarted = false;
852
  // μ˜€λ””μ˜€ κ΄€λ ¨ 속성 μΆ”κ°€
 
 
853
  this.engineSound = null;
854
  this.engineStopSound = null;
855
  this.isEngineRunning = false;
@@ -924,11 +926,14 @@ class Game {
924
 
925
  async initialize() {
926
  try {
927
- // BGM μž¬μƒ μ½”λ“œ μΆ”κ°€
928
- this.bgm = new Audio('sounds/BGM.ogg');
929
- this.bgm.volume = 0.5;
930
- this.bgm.loop = true; // BGM 반볡 μž¬μƒ
931
- this.bgm.play();
 
 
 
932
 
933
  // μ‹œμž‘ μ‚¬μš΄λ“œ μž¬μƒ
934
  const startSounds = ['sounds/start1.ogg', 'sounds/start2.ogg', 'sounds/start3.ogg'];
@@ -1722,6 +1727,12 @@ class Game {
1722
  if (this.isGameOver) return;
1723
 
1724
  this.isGameOver = true;
 
 
 
 
 
 
1725
 
1726
  // 사망 μ‚¬μš΄λ“œ μž¬μƒ
1727
  const deathSounds = ['sounds/death1.ogg', 'sounds/death2.ogg'];
 
850
  // κ²Œμž„ μ‹œμž‘ μ—¬λΆ€λ₯Ό μΆ”μ ν•˜λŠ” ν”Œλž˜κ·Έ μΆ”κ°€
851
  this.isStarted = false;
852
  // μ˜€λ””μ˜€ κ΄€λ ¨ 속성 μΆ”κ°€
853
+ this.bgmPlaying = false; // BGM μž¬μƒ μƒνƒœ 좔적
854
+ this.bgm = null; // BGM μ˜€λ””μ˜€ 객체 μ €μž₯
855
  this.engineSound = null;
856
  this.engineStopSound = null;
857
  this.isEngineRunning = false;
 
926
 
927
  async initialize() {
928
  try {
929
+ // BGM이 아직 μž¬μƒλ˜μ§€ μ•Šμ€ κ²½μš°μ—λ§Œ μž¬μƒ
930
+ if (!this.bgmPlaying && !this.bgm) {
931
+ this.bgm = new Audio('sounds/BGM.ogg');
932
+ this.bgm.volume = 0.5;
933
+ this.bgm.loop = true;
934
+ this.bgm.play();
935
+ this.bgmPlaying = true;
936
+ }
937
 
938
  // μ‹œμž‘ μ‚¬μš΄λ“œ μž¬μƒ
939
  const startSounds = ['sounds/start1.ogg', 'sounds/start2.ogg', 'sounds/start3.ogg'];
 
1727
  if (this.isGameOver) return;
1728
 
1729
  this.isGameOver = true;
1730
+ // BGM 정지
1731
+ if (this.bgm) {
1732
+ this.bgm.pause();
1733
+ this.bgm = null;
1734
+ this.bgmPlaying = false;
1735
+ }
1736
 
1737
  // 사망 μ‚¬μš΄λ“œ μž¬μƒ
1738
  const deathSounds = ['sounds/death1.ogg', 'sounds/death2.ogg'];