cutechicken commited on
Commit
897f660
β€’
1 Parent(s): 9b5680b

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +44 -12
game.js CHANGED
@@ -972,21 +972,42 @@ class Game {
972
 
973
  async initialize() {
974
  try {
975
- // BGM이 아직 μž¬μƒλ˜μ§€ μ•Šμ€ κ²½μš°μ—λ§Œ μž¬μƒ
976
- if (!this.bgmPlaying && !this.bgm) {
977
  this.bgm = new Audio('sounds/BGM.ogg');
978
  this.bgm.volume = 0.5;
979
  this.bgm.loop = true;
980
- this.bgm.play();
981
- this.bgmPlaying = true;
982
  }
983
-
 
 
 
 
 
 
 
 
 
 
 
 
 
984
  // μ‹œμž‘ μ‚¬μš΄λ“œ μž¬μƒ
985
  const startSounds = ['sounds/start1.ogg', 'sounds/start2.ogg', 'sounds/start3.ogg'];
986
  const randomStartSound = startSounds[Math.floor(Math.random() * startSounds.length)];
987
  const startAudio = new Audio(randomStartSound);
988
  startAudio.volume = 0.5;
989
- startAudio.play();
 
 
 
 
 
 
 
 
 
 
990
 
991
  // λ Œλ”λŸ¬ μ„€μ •
992
  this.renderer.shadowMap.enabled = true;
@@ -1884,7 +1905,11 @@ class Game {
1884
 
1885
  // Start game
1886
  window.startGame = function() {
1887
- document.getElementById('startScreen').style.display = 'none';
 
 
 
 
1888
  document.body.requestPointerLock();
1889
 
1890
  if (!window.gameInstance) {
@@ -1893,18 +1918,25 @@ window.startGame = function() {
1893
 
1894
  // κ²Œμž„ μ‹œμž‘ μ„€μ •
1895
  window.gameInstance.isStarted = true;
1896
- window.gameInstance.initialize();
 
 
1897
  };
1898
 
1899
  // Initialize game
1900
  document.addEventListener('DOMContentLoaded', () => {
1901
- // κ²Œμž„ μΈμŠ€ν„΄μŠ€λ§Œ μƒμ„±ν•˜κ³  μ΄ˆκΈ°ν™”λŠ” ν•˜μ§€ μ•ŠμŒ
1902
  window.gameInstance = new Game();
1903
 
1904
- // 기본적인 씬 μ„€μ •λ§Œ μˆ˜ν–‰
1905
  window.gameInstance.setupScene();
1906
- window.gameInstance.animate(); // λ Œλ”λ§ μ‹œμž‘
1907
 
1908
  // μ‹œμž‘ ν™”λ©΄ ν‘œμ‹œ
1909
- document.getElementById('startScreen').style.display = 'block';
 
 
 
 
 
1910
  });
 
972
 
973
  async initialize() {
974
  try {
975
+ // BGM μ΄ˆκΈ°ν™” 및 μž¬μƒ
976
+ if (!this.bgm) {
977
  this.bgm = new Audio('sounds/BGM.ogg');
978
  this.bgm.volume = 0.5;
979
  this.bgm.loop = true;
 
 
980
  }
981
+
982
+ // μ‚¬μš©μž μƒν˜Έμž‘μš© ν›„ BGM μž¬μƒ
983
+ const playBGM = () => {
984
+ if (this.bgm && !this.bgmPlaying) {
985
+ this.bgm.play()
986
+ .then(() => {
987
+ this.bgmPlaying = true;
988
+ })
989
+ .catch(error => {
990
+ console.error('BGM playback failed:', error);
991
+ });
992
+ }
993
+ };
994
+
995
  // μ‹œμž‘ μ‚¬μš΄λ“œ μž¬μƒ
996
  const startSounds = ['sounds/start1.ogg', 'sounds/start2.ogg', 'sounds/start3.ogg'];
997
  const randomStartSound = startSounds[Math.floor(Math.random() * startSounds.length)];
998
  const startAudio = new Audio(randomStartSound);
999
  startAudio.volume = 0.5;
1000
+
1001
+ // μ‹œμž‘ μ‚¬μš΄λ“œ μž¬μƒ ν›„ BGM μ‹œμž‘
1002
+ startAudio.play()
1003
+ .then(() => {
1004
+ playBGM();
1005
+ })
1006
+ .catch(error => {
1007
+ console.error('Start sound playback failed:', error);
1008
+ playBGM(); // μ‹œμž‘ μ‚¬μš΄λ“œ μ‹€νŒ¨ν•΄λ„ BGM μ‹œμž‘
1009
+ });
1010
+
1011
 
1012
  // λ Œλ”λŸ¬ μ„€μ •
1013
  this.renderer.shadowMap.enabled = true;
 
1905
 
1906
  // Start game
1907
  window.startGame = function() {
1908
+ const startScreen = document.getElementById('startScreen');
1909
+ if (startScreen) {
1910
+ startScreen.style.display = 'none';
1911
+ }
1912
+
1913
  document.body.requestPointerLock();
1914
 
1915
  if (!window.gameInstance) {
 
1918
 
1919
  // κ²Œμž„ μ‹œμž‘ μ„€μ •
1920
  window.gameInstance.isStarted = true;
1921
+ window.gameInstance.initialize().catch(error => {
1922
+ console.error('Failed to initialize game:', error);
1923
+ });
1924
  };
1925
 
1926
  // Initialize game
1927
  document.addEventListener('DOMContentLoaded', () => {
1928
+ // κ²Œμž„ μΈμŠ€ν„΄μŠ€ 생성
1929
  window.gameInstance = new Game();
1930
 
1931
+ // 기본적인 씬 μ„€μ •
1932
  window.gameInstance.setupScene();
1933
+ window.gameInstance.animate();
1934
 
1935
  // μ‹œμž‘ ν™”λ©΄ ν‘œμ‹œ
1936
+ const startScreen = document.getElementById('startScreen');
1937
+ if (startScreen) {
1938
+ startScreen.style.display = 'flex';
1939
+ startScreen.style.justifyContent = 'center';
1940
+ startScreen.style.alignItems = 'center';
1941
+ }
1942
  });