we have audio

This commit is contained in:
Srayan Jana
2025-09-24 15:21:48 -07:00
parent 8c83559d85
commit cc28dc00f4
5 changed files with 31 additions and 1 deletions
+3
View File
@@ -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
+5
View File
@@ -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)
Binary file not shown.
+6 -1
View File
@@ -1 +1,6 @@
wall.png texture by [FacadeGaikan](https://opengameart.org/node/31075), licensed under CC0.
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
+17
View File
@@ -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));