add music, better sync, particles
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 2m18s
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 2m18s
This commit is contained in:
57
static/js/audio.js
Normal file
57
static/js/audio.js
Normal file
@@ -0,0 +1,57 @@
|
||||
const SOUNDS = {
|
||||
jump: new Audio('assets/sfx/jump.mp3'),
|
||||
duck: new Audio('assets/sfx/duck.mp3'),
|
||||
coin: new Audio('assets/sfx/coin.mp3'),
|
||||
hit: new Audio('assets/sfx/hit.mp3'),
|
||||
powerup: new Audio('assets/sfx/powerup.mp3'),
|
||||
music: new Audio('assets/sfx/music_loop.mp3')
|
||||
};
|
||||
|
||||
// Config
|
||||
SOUNDS.jump.volume = 0.4;
|
||||
SOUNDS.coin.volume = 0.3;
|
||||
SOUNDS.hit.volume = 0.6;
|
||||
SOUNDS.music.loop = true;
|
||||
SOUNDS.music.volume = 0.2;
|
||||
|
||||
// --- STATUS LADEN ---
|
||||
// Wir lesen den String 'true'/'false' aus dem LocalStorage
|
||||
let isMuted = localStorage.getItem('escape_muted') === 'true';
|
||||
|
||||
function playSound(name) {
|
||||
if (isMuted || !SOUNDS[name]) return;
|
||||
|
||||
const soundClone = SOUNDS[name].cloneNode();
|
||||
soundClone.volume = SOUNDS[name].volume;
|
||||
soundClone.play().catch(() => {});
|
||||
}
|
||||
|
||||
function toggleMute() {
|
||||
isMuted = !isMuted;
|
||||
|
||||
// --- STATUS SPEICHERN ---
|
||||
localStorage.setItem('escape_muted', isMuted);
|
||||
|
||||
// Musik sofort pausieren/starten
|
||||
if(isMuted) {
|
||||
SOUNDS.music.pause();
|
||||
} else {
|
||||
// Nur starten, wenn wir schon im Spiel sind (user interaction needed)
|
||||
// Wir fangen Fehler ab, falls der Browser Autoplay blockiert
|
||||
SOUNDS.music.play().catch(()=>{});
|
||||
}
|
||||
|
||||
return isMuted;
|
||||
}
|
||||
|
||||
function startMusic() {
|
||||
// Nur abspielen, wenn NICHT stummgeschaltet
|
||||
if(!isMuted) {
|
||||
SOUNDS.music.play().catch(e => console.log("Audio Autoplay blocked", e));
|
||||
}
|
||||
}
|
||||
|
||||
// Getter für UI
|
||||
function getMuteState() {
|
||||
return isMuted;
|
||||
}
|
||||
Reference in New Issue
Block a user