feat: Implement combat and movement sound effects with looping footsteps

This commit is contained in:
2026-01-07 20:01:58 +01:00
parent 180cf3ab94
commit 5c5cc13903
3 changed files with 52 additions and 4 deletions

View File

@@ -12,11 +12,15 @@ export class SoundManager {
'exploration': '/assets/music/ingame/Abandoned_Ruins.mp3'
},
sfx: {
'door_open': '/assets/sfx/opendoor.mp3'
'door_open': '/assets/sfx/opendoor.mp3',
'footsteps': '/assets/sfx/footsteps.mp3',
'sword': '/assets/sfx/sword1.mp3',
'arrow': '/assets/sfx/arrow.mp3'
}
};
this.initialized = false;
this.activeLoops = new Map();
}
/**
@@ -112,4 +116,27 @@ export class SoundManager {
// or log if needed
});
}
startLoop(key) {
if (this.isMuted) return;
if (this.activeLoops.has(key)) return; // Already playing
const url = this.assets.sfx[key];
if (!url) return;
const audio = new Audio(url);
audio.loop = true;
audio.volume = this.sfxVolume;
audio.play().catch(() => { });
this.activeLoops.set(key, audio);
}
stopLoop(key) {
const audio = this.activeLoops.get(key);
if (audio) {
audio.pause();
audio.currentTime = 0;
this.activeLoops.delete(key);
}
}
}