-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.lua
70 lines (61 loc) · 1.9 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
local Colors = require 'colors'
local HiScore = require 'hiscore'
local Level = require 'level'
local SharedState = require 'sharedstate'
local Menu = {}
local _TITLE = 'runabout'
local _INSTRUCTIONS = {
'up to thrust',
'left/right to turn',
}
local _START = 'space to start'
local _HISCORE = 'best: '
function Menu:draw()
Level:drawSky()
-- title
Colors.useColor(Colors.Palette.START, Colors.Value.SKYBOTTOM)
local bigFont = SharedState.font.big
love.graphics.setFont(bigFont)
local titleWidth = bigFont:getWidth(_TITLE)
love.graphics.print(
_TITLE,
(SharedState.viewport.width * 0.5) - (titleWidth * 0.5),
100 + (-bigFont:getHeight() * 0.5)
)
-- instructions
local mediumFont = SharedState.font.medium
love.graphics.setFont(mediumFont)
for index, str in pairs(_INSTRUCTIONS) do
local width = mediumFont:getWidth(str)
love.graphics.print(
str,
(SharedState.viewport.width * 0.5) - (width * 0.5),
148 + (index * 32) + (-mediumFont:getHeight() * 0.5)
)
end
-- start
if math.floor(love.timer.getTime() * 6) % 2 == 1 then
Colors.useColor(Colors.Palette.START, Colors.Value.TEXT)
else
love.graphics.setColor(1, 1, 1, 1)
end
local width = mediumFont:getWidth(_START)
love.graphics.print(
_START,
(SharedState.viewport.width * 0.5) - (width * 0.5),
SharedState.viewport.height - 78 + (-mediumFont:getHeight() * 0.5)
)
-- best time
local bestTime = HiScore:get()
if bestTime > 0 then
local timeStr = _HISCORE .. HiScore:formatTime(bestTime)
local width = mediumFont:getWidth(timeStr)
Colors.useColor(Colors.Palette.START, Colors.Value.SKYTOP)
love.graphics.print(
timeStr,
(SharedState.viewport.width * 0.5) - (width * 0.5),
SharedState.viewport.height - 28 + (-mediumFont:getHeight() * 0.5)
)
end
end
return Menu