-
Notifications
You must be signed in to change notification settings - Fork 0
/
sound_and_music.nelua
67 lines (51 loc) · 1.84 KB
/
sound_and_music.nelua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
--[[
Copyright (c) 2021-present André Luiz Alvares
Nene is licensed under the Zlib license.
Please refer to the LICENSE file for details
SPDX-License-Identifier: Zlib
]]
local math = require 'math'
local Nene = require 'nene.core'
local Color = require 'nene.color'
local Sound = require 'nene.audio.sound'
local Music = require 'nene.audio.music'
local function audio_and_music()
-- nene initialization and deferred de-initialization with to-be-closed variable
local ok = Nene.init('nene audio and music', 128, 128)
assert(ok, 'error: nene initialization failed')
defer Nene.terminate() end
-- sound and music loading and deferred destroyment
local ok, click = Sound.load('../../resources/pixelclick.wav')
assert(ok , 'could not load pixelclick sound')
local ok, bossa = Music.load('../../resources/8bit Bossa.ogg')
assert(ok, 'could not load 8bit Bossa music')
defer
click:destroy()
bossa:destroy()
end
local mus_volume, click_volume = 1.0, 1.0
bossa:play()
repeat
Nene.update()
if Nene.is_scancode_pressed(SDL_SCANCODE_P) then
mus_volume = math.clamp(mus_volume + 0.1, 0.0, 1.0)
Music.set_volume(mus_volume)
elseif Nene.is_scancode_pressed(SDL_SCANCODE_O) then
mus_volume = math.clamp(mus_volume - 0.1, 0.0, 1.0)
Music.set_volume(mus_volume)
end
if Nene.is_scancode_pressed(SDL_SCANCODE_M) then
click_volume = math.clamp(click_volume + 0.1, 0.0, 1.0)
click:set_volume(click_volume)
elseif Nene.is_scancode_pressed(SDL_SCANCODE_N) then
click_volume = math.clamp(click_volume - 0.1, 0.0, 1.0)
click:set_volume(click_volume)
end
if Nene.is_scancode_pressed(SDL_SCANCODE_SPACE) or Nene.is_mouse_button_pressed(1) then
click:play()
end
Nene.render_clear(Color.bg)
Nene.render_present()
until Nene.should_quit()
end
audio_and_music()