implement audio playing
This commit is contained in:
79
audio.sex
Normal file
79
audio.sex
Normal file
@@ -0,0 +1,79 @@
|
||||
(include raylib.h)
|
||||
|
||||
(define MENU-CLICK-FILE "res/music/01 - Menu.ogg")
|
||||
(define FISHING-SPOT-FILE "res/music/02 - Fishing Spot.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 menu-music Music)
|
||||
(var game-music Music)
|
||||
(var fishing-music Music)
|
||||
|
||||
;; NULL when no music is playing
|
||||
(var current-music (* Music) NULL)
|
||||
|
||||
(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))
|
||||
(= 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)
|
||||
(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)))
|
||||
|
||||
(pub fn audio-play-menu-click () void
|
||||
(if (IsSoundValid menu-click)
|
||||
(PlaySound menu-click)))
|
||||
|
||||
(pub fn audio-play-fishing-spot () void
|
||||
(if (IsSoundValid fishing-spot-sound)
|
||||
(PlaySound fishing-spot-sound)))
|
||||
Reference in New Issue
Block a user