-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.lua
More file actions
96 lines (84 loc) · 2.24 KB
/
Copy pathmenu.lua
File metadata and controls
96 lines (84 loc) · 2.24 KB
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
require ('parallax')
MENU_START = 0
MENU_CREDITS = 1
MENU_QUIT = 2
class "Menu" {
parent = nil;
cursor = 0;
cursor_max = 2;
font = nil;
color_normal = {0, 127, 255, 127};
color_hover = {255, 127, 0, 255};
quad = nil;
background = nil;
--par = nil;
}
function Menu:__init(parent)
self.parent = parent
self.cursor = 0
self.font = G.newFont(36)
self.background = G.newImage("gfx/titlescreen.png")
--self.par = Parallax:new(10)
end
function Menu:update(dt)
--self.par:update(dt)
end
function Menu:draw()
G.setFont(self.font)
G.draw(self.background, self.quad)
--self.par:draw()
--MENU START
self:setColor(MENU_START)
G.rectangle("fill", gScreenWidth * 0.15 - 128, gScreenHeight * 0.5 - 64 + 0, 256, 42)
G.setColor(0, 0, 0)
G.printf("Start", gScreenWidth * 0.15 - 128, gScreenHeight * 0.5 - 64 + 0, 256, "center")
--MENU CREDITS
self:setColor(MENU_CREDITS)
G.rectangle("fill", gScreenWidth * 0.15 - 128, gScreenHeight * 0.5 - 64 + 48, 256, 42)
G.setColor(0, 0, 0)
G.printf("Credits", gScreenWidth * 0.15 - 128, gScreenHeight * 0.5 - 64 + 48, 256, "center")
--MENU QUIT
self:setColor(MENU_QUIT)
G.rectangle("fill", gScreenWidth * 0.15 - 128, gScreenHeight * 0.5 - 64 + 96, 256, 42)
G.setColor(0, 0, 0)
G.printf("Quit", gScreenWidth * 0.15 - 128, gScreenHeight * 0.5 - 64 + 96, 256, "center")
end
function Menu:keyHit(key)
if key == "up" then
self:up()
elseif key == "down" then
self:down()
elseif key == "return" then
self:enter()
elseif key == "escape" then
love.event.quit()
end
end
function Menu:up()
self.cursor = self.cursor - 1;
if self.cursor < 0 then
self.cursor = self.cursor_max;
end
end
function Menu:down()
self.cursor = self.cursor + 1;
if self.cursor > self.cursor_max then
self.cursor = 0;
end
end
function Menu:enter()
if self.cursor == MENU_START then
self.parent:setState(STATE_GAME)
elseif self.cursor == MENU_CREDITS then
self.parent:setState(STATE_CREDITS)
elseif self.cursor == MENU_QUIT then
love.event.quit()
end
end
function Menu:setColor(position)
if self.cursor == position then
G.setColor(self.color_hover[1], self.color_hover[2], self.color_hover[3], self.color_hover[4])
else
G.setColor(self.color_normal[1], self.color_normal[2], self.color_normal[3], self.color_normal[4])
end
end