114 lines
3.3 KiB
Scheme
114 lines
3.3 KiB
Scheme
(include raylib.h)
|
|
|
|
(define MENU-CLICK-FILE "res/music/01 - Menu.ogg")
|
|
(define FISHING-SPOT-FILE "res/music/02 - Fishing Spot.ogg")
|
|
(define FISHING-START-FILE "res/music/03 - Catch!.ogg")
|
|
(define GOTCHA-FILE "res/music/04 - Gotcha!.ogg")
|
|
(define MENU-MUSIC-FILE "res/music/Catch-Phase 01 - Fishing.ogg")
|
|
(define GAME-MUSIC-FILE "res/music/Catch-Phase 03 - Aqua World.ogg")
|
|
(define FISHING-MUSIC-FILE "res/music/Catch-Phase 05 - FIH.ogg")
|
|
|
|
(var menu-click Sound)
|
|
(var fishing-spot-sound Sound)
|
|
(var fishing-start-sound Sound)
|
|
(var gotcha-sound Sound)
|
|
|
|
(var menu-music Music)
|
|
(var game-music Music)
|
|
(var fishing-music Music)
|
|
|
|
;; NULL when no music is playing
|
|
(var current-music (* Music) NULL)
|
|
(var audio-unlocked bool false)
|
|
|
|
(fn load-sound ((file (* const char))) Sound
|
|
(var sound Sound (LoadSound file))
|
|
(if (! (IsSoundValid sound))
|
|
(TraceLog LOG-WARNING "failed to load sound \"%s\"" file))
|
|
(return sound))
|
|
|
|
(fn load-music ((file (* const char))) Music
|
|
(var music Music (LoadMusicStream file))
|
|
(if (! (IsMusicValid music))
|
|
(TraceLog LOG-WARNING "failed to load music \"%s\"" file))
|
|
(return music))
|
|
|
|
(pub fn audio-init () void
|
|
(= menu-click (load-sound MENU-CLICK-FILE))
|
|
(= fishing-spot-sound (load-sound FISHING-SPOT-FILE))
|
|
(= fishing-start-sound (load-sound FISHING-START-FILE))
|
|
(= gotcha-sound (load-sound GOTCHA-FILE))
|
|
(= menu-music (load-music MENU-MUSIC-FILE))
|
|
(= game-music (load-music GAME-MUSIC-FILE))
|
|
(= fishing-music (load-music FISHING-MUSIC-FILE)))
|
|
|
|
(pub fn audio-deinit () void
|
|
(if (!= current-music NULL)
|
|
(StopMusicStream (* current-music)))
|
|
(= current-music NULL)
|
|
|
|
(UnloadSound menu-click)
|
|
(UnloadSound fishing-spot-sound)
|
|
(UnloadSound fishing-start-sound)
|
|
(UnloadSound gotcha-sound)
|
|
(UnloadMusicStream menu-music)
|
|
(UnloadMusicStream game-music)
|
|
(UnloadMusicStream fishing-music))
|
|
|
|
(fn switch-music ((music (* Music))) void
|
|
(if (== current-music music)
|
|
(return))
|
|
(if (!= current-music NULL)
|
|
(StopMusicStream (* current-music)))
|
|
(= current-music NULL)
|
|
(if (IsMusicValid (* music))
|
|
(do
|
|
(= current-music music)
|
|
(PlayMusicStream (* music)))))
|
|
|
|
(pub fn audio-update () void
|
|
(if (!= current-music NULL)
|
|
(UpdateMusicStream (* current-music))))
|
|
|
|
(pub fn audio-play-menu-music () void
|
|
(switch-music (& menu-music)))
|
|
|
|
(pub fn audio-play-game-music () void
|
|
(switch-music (& game-music)))
|
|
|
|
(pub fn audio-play-fishing-music () void
|
|
(switch-music (& fishing-music)))
|
|
|
|
;; Browsers keep the audio context suspended until the first user gesture.
|
|
;; Restart the current track once after that gesture so the music actually begins.
|
|
#+emscripten
|
|
(pub fn audio-unlock () void
|
|
(if audio-unlocked
|
|
(return))
|
|
(= audio-unlocked true)
|
|
(if (!= current-music NULL)
|
|
(do
|
|
(StopMusicStream (* current-music))
|
|
(PlayMusicStream (* current-music)))))
|
|
|
|
#-emscripten
|
|
(pub fn audio-unlock () void
|
|
(return))
|
|
|
|
(pub fn audio-play-menu-click () void
|
|
(audio-unlock)
|
|
(if (IsSoundValid menu-click)
|
|
(PlaySound menu-click)))
|
|
|
|
(pub fn audio-play-fishing-spot () void
|
|
(if (IsSoundValid fishing-spot-sound)
|
|
(PlaySound fishing-spot-sound)))
|
|
|
|
(pub fn audio-play-fishing-start () void
|
|
(if (IsSoundValid fishing-start-sound)
|
|
(PlaySound fishing-start-sound)))
|
|
|
|
(pub fn audio-play-gotcha () void
|
|
(if (IsSoundValid gotcha-sound)
|
|
(PlaySound gotcha-sound)))
|