diff options
author | Mark Powers <markppowers0@gmail.com> | 2020-04-17 22:56:57 -0500 |
---|---|---|
committer | Mark Powers <markppowers0@gmail.com> | 2020-04-17 22:56:57 -0500 |
commit | ecd8d064a370ce0b9d4a353f6151638b60838208 (patch) | |
tree | e339598839261d8caca078d75b4327f3b034b1f7 /src/cosmic-cargo/static/audio.js | |
parent | 84dca4c6dc0cff9a417ebd0d8f7de06acafa6725 (diff) |
Add cosmic cargo
Diffstat (limited to 'src/cosmic-cargo/static/audio.js')
-rw-r--r-- | src/cosmic-cargo/static/audio.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/cosmic-cargo/static/audio.js b/src/cosmic-cargo/static/audio.js new file mode 100644 index 0000000..3abc79a --- /dev/null +++ b/src/cosmic-cargo/static/audio.js @@ -0,0 +1,40 @@ +var audio = { + "bgm": new Audio("Assets/music.ogg"), + "shop": new Audio("Assets/shop.ogg"), + "encounter": new Audio("Assets/encounter.ogg"), + "endgame": new Audio("Assets/endgame.ogg"), + "gameover": new Audio("Assets/gameover.ogg"), + "alert": new Audio("Assets/SoundEffects/Alert.wav"), + "select": new Audio("Assets/SoundEffects/SelectNoise.wav"), + "move": new Audio("Assets/SoundEffects/MoveCursor.wav"), +} +var music = ["bgm", "shop", "endgame", "gameover", "encounter"] +var sfx = ["alert", "select", "move"] + +function play_audio(sound, loop = false){ + var curr_audio = audio[sound]; + if(curr_audio != undefined){ + if(loop){ + curr_audio.addEventListener('ended', loop_audio_listener, false) + } else { + curr_audio.removeEventListener("ended", loop_audio_listener, false) + } + // play if paused or if not music + if(curr_audio.paused || !music.includes(sound)){ + curr_audio.currentTime = 0; + curr_audio.play(); + } + } +} + +function pause_audio(sound){ + var curr_audio = audio[sound]; + if(curr_audio != undefined){ + curr_audio.pause(); + } +} + +function loop_audio_listener(){ + this.currentTime = 0; + this.play(); +}
\ No newline at end of file |