-
Notifications
You must be signed in to change notification settings - Fork 68
/
options.lua
153 lines (138 loc) · 3.93 KB
/
options.lua
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
options = {}
local lg = love.graphics
function options.enter()
state = STATE_OPTIONS
options.selection = 1
end
function options.update(dt)
updateKeys()
end
function options.draw()
lg.push()
lg.scale(config.scale)
lg.setFont(font.bold)
drawBox(40, 59, 176, 110)
lg.printf("OPTIONS", 0, 37, WIDTH, "center")
lg.print("SCALE:", 65, 71) lg.print(config.scale, 167, 71)
lg.print("VSYNC:", 65, 84) lg.print(config.vsync and "ON" or "OFF", 167, 84)
lg.print("SOUND VOL:", 65, 97) lg.print(math.floor(config.sfx_volume*10+0.01), 167, 97)
lg.print("MUSIC VOL:", 65, 110) lg.print(math.floor(config.music_volume*10+0.01), 167, 110)
lg.print("KEYBOARD", 65, 123)
lg.print("JOYSTICK", 65, 136)
lg.print("BACK", 65, 149)
lg.print(">", 52, 57+options.selection*13)
lg.pop()
end
function options.keypressed(k, uni)
if k == "down" then
options.selection = wrap(options.selection + 1, 1,7)
playSound("blip")
elseif k == "up" then
options.selection = wrap(options.selection - 1, 1,7)
playSound("blip")
elseif k == "left" or k == "right" then
if options.selection == 1 then -- SCALE
if k == "left" then
config.scale = cap(config.scale - 1, 1, 10)
else
config.scale = cap(config.scale + 1, 1, 10)
end
setMode()
playSound("blip")
elseif options.selection == 2 then -- VSYNC
toggleVSync()
playSound("blip")
elseif options.selection == 3 then -- SFX VOLUME
if k == "left" then
config.sfx_volume = cap(config.sfx_volume - 0.1, 0,1)
else
config.sfx_volume = cap(config.sfx_volume + 0.1, 0,1)
end
love.audio.tags.sfx.setVolume(config.sfx_volume)
playSound("blip")
elseif options.selection == 4 then -- MUSIC VOLUME
if k == "left" then
config.music_volume = cap(config.music_volume - 0.1, 0,1)
else
config.music_volume = cap(config.music_volume + 0.1, 0,1)
end
love.audio.tags.music.setVolume(config.music_volume)
playSound("blip")
end
elseif k == "return" then
if options.selection == 2 then -- VSYNC
toggleVSync()
playSound("blip")
elseif options.selection == 5 then -- KEYBOARD
playSound("confirm")
keyboard.enter()
elseif options.selection == 6 then -- JOYSTICK
playSound("confirm")
joystick.enter()
elseif options.selection == 7 then -- BACK
playSound("confirm")
mainmenu.enter()
saveConfig()
end
elseif k == "escape" then
playSound("confirm")
mainmenu.enter()
saveConfig()
end
end
function options.joystickpressed(joy, k)
if k == 3 then
if options.selection == 2 then -- VSYNC
toggleVSync()
playSound("blip")
elseif options.selection == 5 then -- KEYBOARD
playSound("confirm")
keyboard.enter()
elseif options.selection == 6 then -- JOYSTICK
playSound("confirm")
joystick.enter()
elseif options.selection == 7 then -- BACK
playSound("confirm")
mainmenu.enter()
saveConfig()
end
end
end
function options.action(k)
if k == "down" then
options.selection = wrap(options.selection + 1, 1,7)
playSound("blip")
elseif k == "up" then
options.selection = wrap(options.selection - 1, 1,7)
playSound("blip")
elseif k == "left" or k == "right" then
if options.selection == 1 then -- SCALE
if k == "left" then
config.scale = cap(config.scale - 1, 1, 10)
else
config.scale = cap(config.scale + 1, 1, 10)
end
setMode()
playSound("blip")
elseif options.selection == 2 then -- VSYNC
toggleVSync()
playSound("blip")
elseif options.selection == 3 then -- SFX VOLUME
if k == "left" then
config.sfx_volume = cap(config.sfx_volume - 0.1, 0,1)
else
config.sfx_volume = cap(config.sfx_volume + 0.1, 0,1)
end
love.audio.tags.sfx.setVolume(config.sfx_volume)
playSound("blip")
elseif options.selection == 4 then -- MUSIC VOLUME
if k == "left" then
config.music_volume = cap(config.music_volume - 0.1, 0,1)
else
config.music_volume = cap(config.music_volume + 0.1, 0,1)
end
love.audio.tags.music.setVolume(config.music_volume)
playSound("blip")
end
end
end