diff options
| author | ne_mene <[email protected]> | 2026-03-28 22:50:16 +0100 |
|---|---|---|
| committer | ne_mene <[email protected]> | 2026-03-28 22:50:16 +0100 |
| commit | c4e594cc3158bd5ca0979a78bed1017fc7f30d5e (patch) | |
| tree | 1a413463de832379e0e494646b4f5b84d8f006bb | |
| parent | 44af8d899bfbf495b919636dab2ea0184590caf3 (diff) | |
sound module
| -rw-r--r-- | res/sound/thud.mp3 | bin | 0 -> 100310 bytes | |||
| -rw-r--r-- | src/sound.lua | 39 |
2 files changed, 39 insertions, 0 deletions
diff --git a/res/sound/thud.mp3 b/res/sound/thud.mp3 Binary files differnew file mode 100644 index 0000000..1e231e1 --- /dev/null +++ b/res/sound/thud.mp3 diff --git a/src/sound.lua b/src/sound.lua new file mode 100644 index 0000000..4d31861 --- /dev/null +++ b/src/sound.lua @@ -0,0 +1,39 @@ + +local sound_bank = {} + +function load_sounds_from(path) + path = path or "res/sound" + local files = lf.getDirectoryItems(path) + + for _, file in ipairs(files) do + local filepath = path.."/"..file + + if lf.getInfo(filepath).type == "directory" then + load_sounds_from(filepath) + else + if is_filetype(filepath, {"wav", "ogg", "mp3"}) then + sound_bank[filepath] = { + size = 1, + [1] = la.newSource(filepath, "static"), + } + end + end + end +end + +function play_sound(path) + sound = sound_bank[path] + local source = nil + + for i = 1, sound.size do + if not sound[i]:isPlaying() then + source = sound[i] + end + end + if not source then + sound.size = sound.size + 1 + sound[sound.size] = sound[1]:clone() + source = sound[sound.size] + end + la.play(source) +end |
