cutechicken commited on
Commit
d66130a
Β·
verified Β·
1 Parent(s): e487b55

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +58 -52
game.js CHANGED
@@ -58,8 +58,8 @@ class Fighter {
58
  this.lastShootTime = 0;
59
 
60
  // 카메라 μ„€μ •
61
- this.cameraDistance = 250;
62
- this.cameraHeight = 45;
63
  this.cameraLag = 0.1;
64
  }
65
 
@@ -537,6 +537,9 @@ class Game {
537
 
538
  document.getElementById('loading').style.display = 'none';
539
 
 
 
 
540
  this.animate();
541
 
542
  } catch (error) {
@@ -546,6 +549,28 @@ class Game {
546
  }
547
  }
548
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
549
  async preloadEnemies() {
550
  for (let i = 0; i < GAME_CONSTANTS.ENEMY_COUNT; i++) {
551
  const angle = (i / GAME_CONSTANTS.ENEMY_COUNT) * Math.PI * 2;
@@ -682,58 +707,39 @@ class Game {
682
  }
683
 
684
  startBGM() {
685
- if (this.bgmPlaying) return;
686
 
687
- console.log('BGM μ‹œμž‘ μ‹œλ„...');
688
 
689
- try {
690
- this.bgm = new Audio('sounds/main.ogg');
691
- this.bgm.volume = 0.5;
692
- this.bgm.loop = true;
693
-
694
- console.log('Audio 객체 생성 μ™„λ£Œ');
695
-
696
- // μ˜€λ””μ˜€ 이벀트 λ¦¬μŠ€λ„ˆ μΆ”κ°€
697
- this.bgm.addEventListener('loadstart', () => console.log('BGM λ‘œλ”© μ‹œμž‘'));
698
- this.bgm.addEventListener('canplay', () => console.log('BGM μž¬μƒ κ°€λŠ₯'));
699
- this.bgm.addEventListener('error', (e) => console.log('BGM μ—λŸ¬:', e));
700
- this.bgm.addEventListener('loadeddata', () => console.log('BGM 데이터 λ‘œλ“œ μ™„λ£Œ'));
701
-
702
- // μ¦‰μ‹œ μž¬μƒ μ‹œλ„
703
- const playPromise = this.bgm.play();
704
-
705
- console.log('μž¬μƒ μ‹œλ„ 쀑...');
706
-
707
- if (playPromise !== undefined) {
708
- playPromise.then(() => {
709
- this.bgmPlaying = true;
710
- console.log('BGM μž¬μƒ μ‹œμž‘ 성곡!');
711
- }).catch(error => {
712
- console.log('μžλ™ μž¬μƒμ΄ 차단됨:', error);
713
- console.log('클릭 ν›„ μž¬μƒ μ‹œλ„ λŒ€κΈ° 쀑...');
714
-
715
- // μ‚¬μš©μž μƒν˜Έμž‘μš© ν›„ μž¬μƒ μž¬μ‹œλ„
716
- const tryPlayOnInteraction = () => {
717
- if (!this.bgmPlaying) {
718
- console.log('μ‚¬μš©μž μƒν˜Έμž‘μš©μœΌλ‘œ BGM μž¬μƒ μ‹œλ„...');
719
- this.bgm.play().then(() => {
720
- this.bgmPlaying = true;
721
- console.log('BGM μž¬μƒ μ‹œμž‘ 성곡 (클릭 ν›„)!');
722
- // 이벀트 λ¦¬μŠ€λ„ˆ 제거
723
- document.removeEventListener('click', tryPlayOnInteraction);
724
- document.removeEventListener('keydown', tryPlayOnInteraction);
725
- }).catch(e => console.log('BGM μž¬μƒ μ‹€νŒ¨:', e));
726
- }
727
- };
728
-
729
- // ν΄λ¦­μ΄λ‚˜ ν‚€λ³΄λ“œ μž…λ ₯ μ‹œ μž¬μƒ μ‹œλ„
730
- document.addEventListener('click', tryPlayOnInteraction);
731
- document.addEventListener('keydown', tryPlayOnInteraction);
732
- });
733
- }
734
-
735
- } catch (error) {
736
- console.log('BGM μ΄ˆκΈ°ν™” μ‹€νŒ¨:', error);
737
  }
738
  }
739
 
 
58
  this.lastShootTime = 0;
59
 
60
  // 카메라 μ„€μ •
61
+ this.cameraDistance = 60;
62
+ this.cameraHeight = 15;
63
  this.cameraLag = 0.1;
64
  }
65
 
 
537
 
538
  document.getElementById('loading').style.display = 'none';
539
 
540
+ // BGM 사전 λ‘œλ”©
541
+ this.preloadBGM();
542
+
543
  this.animate();
544
 
545
  } catch (error) {
 
549
  }
550
  }
551
 
552
+ preloadBGM() {
553
+ console.log('BGM 사전 λ‘œλ”©...');
554
+
555
+ try {
556
+ this.bgm = new Audio('sounds/main.ogg');
557
+ this.bgm.volume = 0.5;
558
+ this.bgm.loop = true;
559
+
560
+ // μ˜€λ””μ˜€ 이벀트 λ¦¬μŠ€λ„ˆ μΆ”κ°€
561
+ this.bgm.addEventListener('loadstart', () => console.log('BGM λ‘œλ”© μ‹œμž‘'));
562
+ this.bgm.addEventListener('canplay', () => console.log('BGM μž¬μƒ κ°€λŠ₯'));
563
+ this.bgm.addEventListener('error', (e) => console.log('BGM μ—λŸ¬:', e));
564
+ this.bgm.addEventListener('loadeddata', () => console.log('BGM 데이터 λ‘œλ“œ μ™„λ£Œ'));
565
+
566
+ // 파일 사전 λ‘œλ”©
567
+ this.bgm.load();
568
+
569
+ } catch (error) {
570
+ console.log('BGM 사전 λ‘œλ”© μ‹€νŒ¨:', error);
571
+ }
572
+ }
573
+
574
  async preloadEnemies() {
575
  for (let i = 0; i < GAME_CONSTANTS.ENEMY_COUNT; i++) {
576
  const angle = (i / GAME_CONSTANTS.ENEMY_COUNT) * Math.PI * 2;
 
707
  }
708
 
709
  startBGM() {
710
+ if (this.bgmPlaying || !this.bgm) return;
711
 
712
+ console.log('BGM μž¬μƒ μ‹œλ„...');
713
 
714
+ // μ¦‰μ‹œ μž¬μƒ μ‹œλ„
715
+ const playPromise = this.bgm.play();
716
+
717
+ if (playPromise !== undefined) {
718
+ playPromise.then(() => {
719
+ this.bgmPlaying = true;
720
+ console.log('BGM μž¬μƒ μ‹œμž‘ 성곡!');
721
+ }).catch(error => {
722
+ console.log('μžλ™ μž¬μƒμ΄ 차단됨:', error);
723
+ console.log('클릭 ν›„ μž¬μƒ μ‹œλ„ λŒ€κΈ° 쀑...');
724
+
725
+ // μ‚¬μš©μž μƒν˜Έμž‘μš© ν›„ μž¬μƒ μž¬μ‹œλ„
726
+ const tryPlayOnInteraction = () => {
727
+ if (!this.bgmPlaying && this.bgm) {
728
+ console.log('μ‚¬μš©μž μƒν˜Έμž‘μš©μœΌλ‘œ BGM μž¬μƒ μ‹œλ„...');
729
+ this.bgm.play().then(() => {
730
+ this.bgmPlaying = true;
731
+ console.log('BGM μž¬μƒ μ‹œμž‘ 성곡 (클릭 ν›„)!');
732
+ // 이벀트 λ¦¬μŠ€λ„ˆ 제거
733
+ document.removeEventListener('click', tryPlayOnInteraction);
734
+ document.removeEventListener('keydown', tryPlayOnInteraction);
735
+ }).catch(e => console.log('BGM μž¬μƒ μ‹€νŒ¨:', e));
736
+ }
737
+ };
738
+
739
+ // ν΄λ¦­μ΄λ‚˜ ν‚€λ³΄λ“œ μž…λ ₯ μ‹œ μž¬μƒ μ‹œλ„
740
+ document.addEventListener('click', tryPlayOnInteraction);
741
+ document.addEventListener('keydown', tryPlayOnInteraction);
742
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
743
  }
744
  }
745