diff --git a/src/core/AudioManager.ts b/src/core/AudioManager.ts index 080484f..d25b79c 100644 --- a/src/core/AudioManager.ts +++ b/src/core/AudioManager.ts @@ -1,24 +1,39 @@ import { Howl } from "howler"; export class AudioManager { + soundFiles = [ + { name: "soundtrack.ogg", src: "./assets/Audio/Musics/soundtrack.ogg" }, + { name: "shot_orange.wav", src: "./assets/Audio/Sounds/shot_orange.wav" }, + { name: "shot_green.wav", src: "./assets/Audio/Sounds/shot_green.wav" }, + { name: "shot_blue.wav", src: "./assets/Audio/Sounds/shot_blue.wav" }, + { name: "shot_enemy_weak.wav", src: "./assets/Audio/Sounds/shot_enemy_weak.wav" }, + { name: "shot_enemy_strong.wav", src: "./assets/Audio/Sounds/shot_enemy_strong.wav" }, + { name: "gethit.ogg", src: "./assets/Audio/Sounds/gethit.ogg" }, + { name: "death.wav", src: "./assets/Audio/Sounds/death.wav" }, + ]; + sounds: { [key: string]: Howl } = {}; + constructor() { + this.preloadAudioFiles(); this.playSoundtrack(); } - - playSoundtrack() { - const sound = new Howl({ - src: ["./assets/Audio/Musics/soundtrack.ogg"], - loop: true, - volume: 0.05, + preloadAudioFiles(): void { + this.soundFiles.forEach((soundFile) => { + this.sounds[soundFile.name] = new Howl({ + src: [soundFile.src], + preload: true, + }); }); - sound.play(); } - - playSound(soundName: string, soundVolume: number = 1) { - const sound = new Howl({ - src: [`./assets/Audio/Sounds/${soundName}`], - volume: soundVolume, - }); + playSoundtrack(): void { + const soundtrack = this.sounds["soundtrack.ogg"]; + soundtrack.loop(true); + soundtrack.volume(0.05); + soundtrack.play(); + } + playSound(soundName: string, soundVolume: number = 1): void { + const sound = this.sounds[soundName]; + sound.volume(soundVolume); sound.play(); } }