-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscene_menu.lua
More file actions
204 lines (162 loc) · 5.28 KB
/
scene_menu.lua
File metadata and controls
204 lines (162 loc) · 5.28 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
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
--
-- scene_menu.lua
-- redditgamejam-05
--
-- Created by Jay Roberts on 2011-01-06.
-- Copyright 2011 GloryFish.org. All rights reserved.
--
require 'vector'
-- Game scenes
require 'scene_game'
require 'scene_instructions'
menu = Gamestate.new()
function menu.enter(self, pre)
menu.title = 'Unrequited'
menu.subtitle = 'a game by Jay Roberts'
menu.bird = love.graphics.newImage('resources/images/menubird.png')
menu.redditlogo = love.graphics.newImage('resources/images/redditgamejam05.png')
menu.heart = love.graphics.newImage('resources/images/heart.png')
menu.heart:setFilter('nearest', 'nearest')
menu.sounds = {
menuselect = love.audio.newSource('resources/sounds/menuselect.mp3', 'static'),
menumove = love.audio.newSource('resources/sounds/menumove.mp3', 'static')
}
menu.entries = {
{
title = 'Play',
scene = game,
level = 'levelone'
},
{
title = 'How to play',
scene = instructions,
},
{
title = 'Quit'
}
}
menu.colors = {
text = {
r = 255,
g = 255,
b = 255,
a = 255
},
highlight = {
r = 255,
g = 0,
b = 0,
a = 255
},
background = {
r = 200,
g = 200,
b = 250,
a = 255
}
}
menu.position = vector(70, 100)
menu.lineHeight = 30
menu.index = 1
music.title:setVolume(1.0)
love.audio.play(music.title)
menu.leaving = false
menu.leaveInterval = 1
menu.leaveDuration = 0
end
function menu.update(self, dt)
if menu.leaving then
menu.leaveDuration = menu.leaveDuration + dt
music.title:setVolume(1 - ((menu.leaveInterval - menu.leaveDuration) / menu.leaveInterval))
if menu.leaveDuration > menu.leaveInterval then
menu.leaving = false
love.audio.stop(music.title)
Gamestate.switch(menu.entries[menu.index].scene)
end
else
input:update(dt)
if input.state.buttons.newpress.down then
menu.index = menu.index + 1
if menu.index > #menu.entries then
menu.index = 1
end
love.audio.play(self.sounds.menumove)
end
if input.state.buttons.newpress.up then
menu.index = menu.index - 1
if menu.index < 1 then
menu.index = #menu.entries
end
love.audio.play(self.sounds.menumove)
end
if input.state.buttons.newpress.select then
if menu.entries[menu.index].title == 'Quit' then
love.event.push('quit')
else
if menu.entries[menu.index].level ~= nil then
menu.entries[menu.index].scene.level = menu.entries[menu.index].level
end
menu.leaving = true
menu.leaveDuration = 0
love.audio.play(self.sounds.menuselect)
end
end
if input.state.buttons.newpress.cancel then
love.event.push('quit')
end
end
end
function menu.draw(self)
love.graphics.setFont(fonts.large)
love.graphics.setColor(50, 50, 50, 200)
love.graphics.print(menu.title, 39, 19);
love.graphics.setColor(self.colors.text.r,
self.colors.text.g,
self.colors.text.b,
self.colors.text.a);
love.graphics.print(menu.title, 40, 20);
love.graphics.setFont(fonts.default)
love.graphics.setColor(50, 50, 50, 200)
love.graphics.print(menu.subtitle, 39, 59);
love.graphics.setColor(self.colors.text.r,
self.colors.text.g,
self.colors.text.b,
self.colors.text.a);
love.graphics.print(menu.subtitle, 40, 60);
love.graphics.setBackgroundColor(self.colors.background.r,
self.colors.background.g,
self.colors.background.b,
self.colors.background.a);
local currentLinePosition = 0
for index, entry in pairs(self.entries) do
love.graphics.setColor(50, 50, 50, 200)
love.graphics.print(entry.title,
self.position.x - 1,
self.position.y + currentLinePosition - 1);
love.graphics.setColor(self.colors.text.r,
self.colors.text.g,
self.colors.text.b,
self.colors.text.a);
if index == self.index then
love.graphics.setColor(self.colors.highlight.r,
self.colors.highlight.g,
self.colors.highlight.b,
self.colors.highlight.a);
love.graphics.draw(self.heart, self.position.x - 20, self.position.y + currentLinePosition + 10, 0, 2, 2, 8, 8)
end
love.graphics.print(entry.title,
self.position.x,
self.position.y + currentLinePosition);
currentLinePosition = currentLinePosition + self.lineHeight;
end
love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(menu.redditlogo, 500, 500)
love.graphics.draw(menu.bird, 660, 50, 0, -1 * 0.9, 1 * 0.9)
if menu.leaving then
local overlayAlpha = (1 - ((menu.leaveInterval - menu.leaveDuration) / menu.leaveInterval)) * 255
love.graphics.setColor(255, 255, 255, overlayAlpha)
love.graphics.rectangle('fill', 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
end
end
function menu.leave(self)
end