Spaces:
Running
Running
cutechicken
commited on
Commit
β’
897f660
1
Parent(s):
9b5680b
Update game.js
Browse files
game.js
CHANGED
@@ -972,21 +972,42 @@ class Game {
|
|
972 |
|
973 |
async initialize() {
|
974 |
try {
|
975 |
-
// BGM
|
976 |
-
if (!this.
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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')
|
|
|
|
|
|
|
|
|
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')
|
|
|
|
|
|
|
|
|
|
|
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 |
});
|