diff --git a/SDL.lean b/SDL.lean index 5333afb..c187f96 100644 --- a/SDL.lean +++ b/SDL.lean @@ -65,6 +65,9 @@ opaque loadTexture : String → IO UInt32 @[extern "sdl_load_font"] opaque loadFont : String → UInt32 → IO Bool +@[extern "sdl_load_track"] +opaque loadTrack : String → IO Bool + @[extern "sdl_render_texture"] opaque renderTexture (x : Int32) (y : Int32) (w : Int32) (h : Int32) : IO Int32 diff --git a/TestApp.lean b/TestApp.lean index 0c13b6e..8de913d 100644 --- a/TestApp.lean +++ b/TestApp.lean @@ -110,6 +110,11 @@ partial def run : IO Unit := do SDL.quit return + unless (← SDL.loadTrack "assets/In_The_Dark_Flashes.mp3") do + IO.println "Failed to load audio track" + SDL.quit + return + let initialState : EngineState := { deltaTime := 0.0, lastTime := 0, running := true playerX := (SCREEN_WIDTH / 2), playerY := (SCREEN_HEIGHT / 2) diff --git a/assets/In_The_Dark_Flashes.mp3 b/assets/In_The_Dark_Flashes.mp3 new file mode 100644 index 0000000..0126aff Binary files /dev/null and b/assets/In_The_Dark_Flashes.mp3 differ diff --git a/assets/LICENSE.md b/assets/LICENSE.md index 126c6c0..9d77a95 100644 --- a/assets/LICENSE.md +++ b/assets/LICENSE.md @@ -1 +1,6 @@ -wall.png texture by [FacadeGaikan](https://opengameart.org/node/31075), licensed under CC0. \ No newline at end of file +wall.png texture by [FacadeGaikan](https://opengameart.org/node/31075), licensed under CC0. + +Jess Stacy "In The Dark-Flashes" +Written by Bix Beiderbeck (1903-1931) +From https://www.openmusicarchive.org +Public Domain \ No newline at end of file diff --git a/c/sdl.c b/c/sdl.c index 0414f4e..5918a3f 100644 --- a/c/sdl.c +++ b/c/sdl.c @@ -158,6 +158,23 @@ lean_obj_res sdl_load_font(lean_obj_arg fontname, uint32_t font_size, lean_obj_a return lean_io_result_mk_ok(lean_box(1)); } +// TODO: This plays the track immediatly after loading it, which should not be the case +lean_obj_res sdl_load_track(lean_obj_arg trackname, lean_obj_arg w) { + MIX_Track* mixerTrack = MIX_CreateTrack(mixer); + const char* trackname_str = lean_string_cstr(trackname); + MIX_Audio* track = MIX_LoadAudio(mixer, trackname_str, false); + if (!track) { + SDL_Log("C: Failed to load track: %s\n", SDL_GetError()); + return lean_io_result_mk_ok(lean_box(0)); + } + + // play the track (does not loop) + MIX_SetTrackAudio(mixerTrack, track); + MIX_PlayTrack(mixerTrack, 0); + + return lean_io_result_mk_ok(lean_box(1)); +} + // TODO: VERY inefficient text rendering, re-renders entire text each time lean_obj_res sdl_render_text(lean_obj_arg text, uint32_t dst_x, uint32_t dst_y, uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha, lean_obj_arg w) { if (!g_renderer || !font) return lean_io_result_mk_ok(lean_box_uint32(0));