From fa1aa7793bbe2a3647435798c56f43945278bcd0 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Mon, 11 Aug 2025 12:21:24 +0200 Subject: Added load, play and stop sound functions --- tests/sounds/effect1.wav | Bin 0 -> 26182 bytes tests/sounds/song1.ogg | Bin 0 -> 103277 bytes tests/test.lua | 23 +++++++++++++++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/sounds/effect1.wav create mode 100644 tests/sounds/song1.ogg (limited to 'tests') diff --git a/tests/sounds/effect1.wav b/tests/sounds/effect1.wav new file mode 100644 index 0000000..209c609 Binary files /dev/null and b/tests/sounds/effect1.wav differ diff --git a/tests/sounds/song1.ogg b/tests/sounds/song1.ogg new file mode 100644 index 0000000..4a47527 Binary files /dev/null and b/tests/sounds/song1.ogg differ diff --git a/tests/test.lua b/tests/test.lua index 372b221..67df27a 100644 --- a/tests/test.lua +++ b/tests/test.lua @@ -10,6 +10,9 @@ test_camera_position = { x = 0, y = 0 } test_camera_speed = 200 test_images_asset1 = load_image("tests/icons/icon_1.png") test_images_asset2 = load_image("tests/icons/icon_2.png") +test_sounds_sound1 = load_sound("tests/sounds/effect1.wav") +test_sounds_sound2 = load_sound("tests/sounds/song1.ogg") +test_sounds_volume = 100 function test_api() draw_rect(100, 100, 300, 200, color.YELLOW) @@ -140,13 +143,28 @@ function test_camera() end function test_images() - draw_text(string.format("uid: %s", test_images_asset1), 50, 50, 20, color.VIOLET) - draw_text(string.format("uid: %s", test_images_asset2), 50, 80, 20, color.VIOLET) + draw_text(string.format("uid: %s", test_images_asset1), 30, 30, 20, color.VIOLET) + draw_text(string.format("uid: %s", test_images_asset2), 30, 55, 20, color.VIOLET) draw_image(test_images_asset1, 150, 150) draw_image(test_images_asset2, 200, 200) end +function test_sounds() + draw_text("Press button A to play a short sound effect.", 30, 30, 20, color.BLUE) + draw_text("Press button B to play a longer sound effect.", 30, 55, 20, color.BLUE) + + if button_pressed(button.A) then + draw_text("Button A pressed", 30, 85, 20, color.YELLOW) + play_sound(test_sounds_sound1) + end + + if button_pressed(button.B) then + draw_text("Button B pressed", 30, 85, 20, color.YELLOW) + play_sound(test_sounds_sound2) + end +end + while window_running() do start_drawing() clear_window(color.BLACK) @@ -156,6 +174,7 @@ while window_running() do -- test_buttons() -- test_camera() -- test_images() + -- test_sounds() draw_info() stop_drawing() -- cgit v1.2.3