cutechicken commited on
Commit
30a3fb9
Β·
verified Β·
1 Parent(s): ef9fa71

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +63 -30
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
 
@@ -505,6 +505,7 @@ class Game {
505
  this.fighter = new Fighter();
506
  this.enemies = [];
507
  this.isLoaded = false;
 
508
  this.isGameOver = false;
509
  this.gameTime = GAME_CONSTANTS.MISSION_DURATION;
510
  this.score = 0;
@@ -538,10 +539,11 @@ class Game {
538
  this.isLoaded = true;
539
  console.log('κ²Œμž„ λ¦¬μ†ŒμŠ€ λ‘œλ”© μ™„λ£Œ');
540
 
541
- document.getElementById('loading').style.display = 'none';
542
-
543
  // BGM 사전 λ‘œλ”©
544
- this.preloadBGM();
 
 
 
545
 
546
  this.animate();
547
 
@@ -552,26 +554,53 @@ class Game {
552
  }
553
  }
554
 
555
- preloadBGM() {
 
 
 
 
 
 
 
556
  console.log('BGM 사전 λ‘œλ”©...');
557
 
558
- try {
559
- this.bgm = new Audio('sounds/main.ogg');
560
- this.bgm.volume = 0.5;
561
- this.bgm.loop = true;
562
-
563
- // μ˜€λ””μ˜€ 이벀트 λ¦¬μŠ€λ„ˆ μΆ”κ°€
564
- this.bgm.addEventListener('loadstart', () => console.log('BGM λ‘œλ”© μ‹œμž‘'));
565
- this.bgm.addEventListener('canplay', () => console.log('BGM μž¬μƒ κ°€λŠ₯'));
566
- this.bgm.addEventListener('error', (e) => console.log('BGM μ—λŸ¬:', e));
567
- this.bgm.addEventListener('loadeddata', () => console.log('BGM 데이터 λ‘œλ“œ μ™„λ£Œ'));
568
-
569
- // 파일 사전 λ‘œλ”©
570
- this.bgm.load();
571
-
572
- } catch (error) {
573
- console.log('BGM 사전 λ‘œλ”© μ‹€νŒ¨:', error);
574
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
575
  }
576
 
577
  async preloadEnemies() {
@@ -946,16 +975,20 @@ let gameInstance = null;
946
 
947
  // μ „μ—­ ν•¨μˆ˜
948
  window.startGame = function() {
 
 
 
 
 
 
 
 
949
  document.getElementById('startScreen').style.display = 'none';
950
  document.body.requestPointerLock();
951
 
952
- if (gameInstance && gameInstance.isLoaded) {
953
- // μ¦‰μ‹œ BGM μž¬μƒ μ‹œλ„ (μ‚¬μš©μž 클릭 μ‹œμ )
954
- gameInstance.startBGM();
955
- gameInstance.startGame();
956
- } else {
957
- console.log('κ²Œμž„μ΄ 아직 μ€€λΉ„λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€...');
958
- }
959
  };
960
 
961
  // κ²Œμž„ μ΄ˆκΈ°ν™”
 
58
  this.lastShootTime = 0;
59
 
60
  // 카메라 μ„€μ •
61
+ this.cameraDistance = 60;
62
+ this.cameraHeight = 15;
63
  this.cameraLag = 0.1;
64
  }
65
 
 
505
  this.fighter = new Fighter();
506
  this.enemies = [];
507
  this.isLoaded = false;
508
+ this.isBGMReady = false;
509
  this.isGameOver = false;
510
  this.gameTime = GAME_CONSTANTS.MISSION_DURATION;
511
  this.score = 0;
 
539
  this.isLoaded = true;
540
  console.log('κ²Œμž„ λ¦¬μ†ŒμŠ€ λ‘œλ”© μ™„λ£Œ');
541
 
 
 
542
  // BGM 사전 λ‘œλ”©
543
+ await this.preloadBGM();
544
+
545
+ // λͺ¨λ“  λ¦¬μ†ŒμŠ€ λ‘œλ”© μ™„λ£Œ ν›„ λ‘œλ”© ν™”λ©΄ 숨기기
546
+ this.checkAllResourcesReady();
547
 
548
  this.animate();
549
 
 
554
  }
555
  }
556
 
557
+ checkAllResourcesReady() {
558
+ if (this.isLoaded && this.isBGMReady) {
559
+ document.getElementById('loading').style.display = 'none';
560
+ console.log('λͺ¨λ“  λ¦¬μ†ŒμŠ€ μ€€λΉ„ μ™„λ£Œ - κ²Œμž„ μ‹œμž‘ κ°€λŠ₯');
561
+ }
562
+ }
563
+
564
+ async preloadBGM() {
565
  console.log('BGM 사전 λ‘œλ”©...');
566
 
567
+ return new Promise((resolve, reject) => {
568
+ try {
569
+ this.bgm = new Audio('sounds/main.ogg');
570
+ this.bgm.volume = 0.5;
571
+ this.bgm.loop = true;
572
+
573
+ // BGM λ‘œλ”© μ™„λ£Œ 이벀트
574
+ this.bgm.addEventListener('canplaythrough', () => {
575
+ console.log('BGM μž¬μƒ μ€€λΉ„ μ™„λ£Œ');
576
+ this.isBGMReady = true;
577
+ resolve();
578
+ });
579
+
580
+ this.bgm.addEventListener('error', (e) => {
581
+ console.log('BGM μ—λŸ¬:', e);
582
+ this.isBGMReady = true; // μ—λŸ¬κ°€ λ‚˜λ”λΌλ„ κ²Œμž„μ€ μ‹œμž‘ν•  수 있게
583
+ resolve();
584
+ });
585
+
586
+ // 파일 사전 λ‘œλ”©
587
+ this.bgm.load();
588
+
589
+ // νƒ€μž„μ•„μ›ƒ μ„€μ • (5초 후에도 λ‘œλ”©μ΄ μ•ˆλ˜λ©΄ κ°•μ œλ‘œ μ™„λ£Œ)
590
+ setTimeout(() => {
591
+ if (!this.isBGMReady) {
592
+ console.log('BGM λ‘œλ”© νƒ€μž„μ•„μ›ƒ - κ²Œμž„ μ§„ν–‰');
593
+ this.isBGMReady = true;
594
+ resolve();
595
+ }
596
+ }, 5000);
597
+
598
+ } catch (error) {
599
+ console.log('BGM 사전 λ‘œλ”© μ‹€νŒ¨:', error);
600
+ this.isBGMReady = true; // μ—λŸ¬κ°€ λ‚˜λ”λΌλ„ κ²Œμž„μ€ μ‹œμž‘ν•  수 있게
601
+ resolve();
602
+ }
603
+ });
604
  }
605
 
606
  async preloadEnemies() {
 
975
 
976
  // μ „μ—­ ν•¨μˆ˜
977
  window.startGame = function() {
978
+ // κ²Œμž„κ³Ό BGM이 λͺ¨λ‘ μ€€λΉ„λ˜μ—ˆλŠ”μ§€ 확인
979
+ if (!gameInstance || !gameInstance.isLoaded || !gameInstance.isBGMReady) {
980
+ console.log('κ²Œμž„μ΄ 아직 μ€€λΉ„λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€...');
981
+ console.log('κ²Œμž„ λ‘œλ”©:', gameInstance?.isLoaded ? 'μ™„λ£Œ' : '진행쀑');
982
+ console.log('BGM μ€€λΉ„:', gameInstance?.isBGMReady ? 'μ™„λ£Œ' : '진행쀑');
983
+ return;
984
+ }
985
+
986
  document.getElementById('startScreen').style.display = 'none';
987
  document.body.requestPointerLock();
988
 
989
+ // μ¦‰μ‹œ BGM μž¬μƒ μ‹œλ„ (μ‚¬μš©μž 클릭 μ‹œμ )
990
+ gameInstance.startBGM();
991
+ gameInstance.startGame();
 
 
 
 
992
  };
993
 
994
  // κ²Œμž„ μ΄ˆκΈ°ν™”