Debian Codegraph @

dokidoki/examples/sound.lua

raw symbols SCIP
1 require "dokidoki.module" [[]]
2
3 require "glfw"
4
5 kernel = require "dokidoki.kernel"
6 mixer = require 'mixer'
7
8 function make_sound_scene ()
9 local sfx = false
10 local sfx2 = false
11
12 local function handle_event (event)
13 if event.type == 'quit' or
14 event.type == 'key' and event.is_down and event.key == glfw.KEY_ESC then
15 kernel.abort_main_loop()
16 elseif event.type == 'key' and event.is_down
17 and event.key == ("1"):byte() then
18 if not sfx then sfx = mixer.load_wav("brouing.wav") end
19 sfx:play()
20 elseif event.type == 'key' and event.is_down
21 and event.key == ("2"):byte() then
22 if not sfx2 then sfx2 = mixer.load_wav("blip.wav") end
23 sfx2:play()
24 elseif event.type == 'key' and event.is_down
25 and event.key == ("3"):byte() then
26 if not sfx then sfx = mixer.load_wav("brouing.wav") end
27 local channel = sfx:play(1, 0)
28 mixer.channel_fade_to(channel, 0.5, 0, 1)
29 end
30 end
31
32 local do_nothing = function () end
33
34 return {handle_event = handle_event, update = do_nothing, draw = do_nothing}
35 end
36
37 kernel.start_main_loop(make_sound_scene())
38