-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmenu.lua
256 lines (223 loc) · 6.39 KB
/
menu.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
local lg = love.graphics
Menu = {}
Menu.__index = Menu
function Menu.create(names, functions, escape_function)
local self = {}
setmetatable(self, Menu)
self.names = names
self.functions = functions
self.length = #names
self.escape_function = escape_function
self.width = 0
for i,v in ipairs(names) do
local w = fontBold:getWidth("* "..v.." *")
self.width = math.max(self.width, w)
end
self.height = 16*self.length-9
self.selected = 1
return self
end
function Menu:keypressed(k)
if k == "down" then
self.selected = self.selected + 1
love.audio.play(snd.Blip)
if self.selected > self.length then
self.selected = 1
end
elseif k == "up" then
self.selected = self.selected - 1
love.audio.play(snd.Blip)
if self.selected == 0 then
self.selected = self.length
end
elseif k == "return" then
love.audio.play(snd.Blip)
if self.functions[self.selected] then
self.functions[self.selected](self)
end
elseif k == "escape" then
love.audio.play(snd.Blip)
self.escape_function(self)
end
end
function Menu:draw()
local top = (HEIGHT-self.height)/2
lg.setColor(COLORS.menu)
lg.rectangle("fill",(WIDTH-self.width)/2-6, top-6, self.width+12, self.height+12)
lg.setColor(1,1,1,1)
lg.setFont(fontBold)
for i=1,self.length do
if i == self.selected then
lg.printf("* "..self.names[i].." *", 0, top+(i-1)*16, WIDTH, "center")
else
lg.printf(self.names[i], 0, top+(i-1)*16, WIDTH, "center")
end
end
end
local host = require('hostinfo')
function createMenus()
-- INGAME MENU
local menuItems = {"CONTINUE", "RESTART LEVEL", "OPTIONS", "EXIT LEVEL", "QUIT GAME"}
if host.isTouchDevice() then
table.remove(menuItems, #menuItems)
end
ingame_menu = Menu.create(
menuItems,
{function() gamestate = STATE_INGAME end,
function() reloadMap() gamestate = STATE_INGAME end,
function() current_menu = options_menu end,
function() gamestate = STATE_LEVEL_MENU end,
function() love.event.quit() end},
function() gamestate = STATE_INGAME end
)
-- OPTIONS MENU
options_menu = Menu.create(
{"SCALE: X", "CAMERA SPEED: |=======|",
"MUSIC VOLUME: |==========|", "SOUND VOLUME: |==========|", "BACK"},
{nil,nil,nil,nil,
function() if gamestate == STATE_INGAME_MENU then current_menu = ingame_menu
else current_menu = main_menu end end},
function() if gamestate == STATE_INGAME_MENU then current_menu = ingame_menu
else current_menu = main_menu end end
)
function options_menu:update()
self.names = {
"SCALE: "..SCALE,
"CAMERA SPEED: |"..string.rep("=",SCROLL_SPEED-2)..string.rep("-",9-SCROLL_SPEED).."|",
"MUSIC VOLUME: |"..string.rep("=",music_volume*10)..string.rep("-",10-music_volume*10).."|",
"SOUND VOLUME: |"..string.rep("=",sound_volume*10)..string.rep("-",10-sound_volume*10).."|",
"BACK"
}
end
options_menu:update()
options_menu.metakeypressed = options_menu.keypressed
function options_menu:keypressed(k)
if k == "left" then
if self.selected == 1 then
setScale(SCALE-1)
love.audio.play(snd.Blip)
elseif self.selected == 2 then
if SCROLL_SPEED > 3 then
SCROLL_SPEED = SCROLL_SPEED - 1
love.audio.play(snd.Blip)
else
love.audio.play(snd.Blip2)
end
elseif self.selected == 3 then
if music_volume >= 0.1 then
music_volume = music_volume - 0.1
updateVolumes()
love.audio.play(snd.Blip)
else
love.audio.play(snd.Blip2)
end
elseif self.selected == 4 then
if sound_volume >= 0.1 then
sound_volume = sound_volume - 0.1
updateVolumes()
love.audio.play(snd.Blip)
else
love.audio.play(snd.Blip2)
end
end
self:update()
elseif k == "right" then
if self.selected == 1 then
setScale(SCALE+1)
love.audio.play(snd.Blip)
elseif self.selected == 2 then
if SCROLL_SPEED < 9 then
SCROLL_SPEED = SCROLL_SPEED + 1
love.audio.play(snd.Blip)
else
love.audio.play(snd.Blip2)
end
elseif self.selected == 3 then
if music_volume <= 0.9 then
music_volume = music_volume + 0.1
updateVolumes()
love.audio.play(snd.Blip)
else
love.audio.play(snd.Blip2)
end
elseif self.selected == 4 then
if sound_volume <= 0.9 then
sound_volume = sound_volume + 0.1
updateVolumes()
love.audio.play(snd.Blip)
else
love.audio.play(snd.Blip2)
end
end
self:update()
else
self:metakeypressed(k)
end
end
-- MAIN MENU
local menuItems = {"START GAME", "OPTIONS", "STATS", "CREDITS", "QUIT GAME"}
if host.isTouchDevice() then
table.remove(menuItems, #menuItems)
end
main_menu = Menu.create(
menuItems,
{function() gamestate = STATE_LEVEL_MENU end,
function() current_menu = options_menu end,
function() current_menu = stats_menu end,
function() current_menu = credits_menu end,
function() love.event.quit() end},
function() love.event.quit() end
)
function main_menu:draw()
lg.setColor(1,1,1,1)
for i=1,self.length do
if i == self.selected then
lg.printf("* "..self.names[i].." *", 123, 59+(i-1)*12, 166, "center")
else
lg.printf(self.names[i], 123, 59+(i-1)*12, 166, "center")
end
end
end
-- credits menu
credits_menu = Menu.create(
{"GRAPHICS AND PROGRAMMING","SIMON LARSEN","TITLE SCREEN",
"LUKAS HANSEN","MUSIC","RUGAR - A SCENT OF EUROPE","SEE LICENCE.TXT FOR MORE INFO"},
nil,nil
)
function credits_menu:draw()
local top = (HEIGHT-self.height)/2
lg.setColor(COLORS.menu)
lg.rectangle("fill",(WIDTH-self.width)/2-6, top-6, self.width+12, self.height+12)
lg.setColor(1,1,1,1)
lg.setFont(fontBold)
local offset = top+8
for i=1,self.length do
lg.printf(self.names[i], 0, offset, WIDTH, "center")
offset = offset + 10
if (i%2) == 0 then offset = offset + 8 end
end
end
function credits_menu:keypressed(k)
love.audio.play(snd.Blip)
current_menu = main_menu
end
-- stats menu
stats_menu = Menu.create(
{"TOTAL DEATHS: XXX", "TOTAL JUMPS: XXXX", "COINS COLLECTED: 00/45"},
nil, nil
)
function stats_menu:draw()
local top = (HEIGHT-self.height)/2
lg.setColor(COLORS.menu)
lg.rectangle("fill",(WIDTH-self.width)/2-6, top-6, self.width+12, self.height+12)
lg.setColor(1,1,1,1)
lg.setFont(fontBold)
lg.printf("TOTAL DEATHS: "..deaths, 0, top, WIDTH, "center")
lg.printf("TOTAL JUMPS: "..jumps, 0, top+16, WIDTH, "center")
lg.printf("COINS COLLECTED: "..coins.."/45", 0, top+32, WIDTH, "center")
end
function stats_menu:keypressed(k)
love.audio.play(snd.Blip)
current_menu = main_menu
end
end