feat: Implement combat and movement sound effects with looping footsteps
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user