Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
@@ -58,8 +58,8 @@ class Fighter {
|
|
58 |
this.lastShootTime = 0;
|
59 |
|
60 |
// μΉ΄λ©λΌ μ€μ
|
61 |
-
this.cameraDistance =
|
62 |
-
this.cameraHeight =
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
556 |
console.log('BGM μ¬μ λ‘λ©...');
|
557 |
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
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 |
-
|
953 |
-
|
954 |
-
|
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 |
// κ²μ μ΄κΈ°ν
|