-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathpauseGameState.lua
78 lines (66 loc) · 1.88 KB
/
pauseGameState.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
local State = require("state")
local LevelSelectionState = require("levelSelectionState")
local Cursor = require("cursor")
local Menu = require("menu")
local CountdownState = require("countdownState")
local Label = require("label")
local PauseGameState = {}
PauseGameState.__index = PauseGameState
setmetatable(PauseGameState, State)
function PauseGameState.create(parent)
local self = setmetatable(State.create(), PauseGameState)
self:addComponent(Label.create("PAUSE", 0, 94, WIDTH, "center"))
self.menu = self:addComponent(Menu.create((WIDTH-200)/2, 143, 200, 32, 24, self))
self.menu:addButton("CONTINUE", "continue")
self.menu:addButton("RESTART", "restart")
self.menu:addButton("SELECT LEVEL", "selectlevel")
self.menu:addButton("QUIT", "quit")
self.cursors[1] = Cursor.create(WIDTH/2, HEIGHT/2, 1)
for i=1,4 do
if parent.inputs[i]:getType() == Input.TYPE_BOT then
self.inputs[i] = NullInput.create()
else
self.inputs[i] = parent.inputs[i]
end
self.cursors[1]:addInput(self.inputs[i])
end
self.mapname = parent.mapname
return self
end
function PauseGameState:update()
for i=1,4 do
if self.inputs[i]:wasMenuPressed() then
popState()
end
end
end
function PauseGameState:draw()
love.graphics.setColor(0, 0, 0, 128)
love.graphics.rectangle("fill", 0, 0, WIDTH, HEIGHT)
love.graphics.setColor(255,255,255,255)
end
function PauseGameState:buttonPressed(id, source)
if id == "continue" then
playSound("quack")
popState()
elseif id == "restart" then
playSound("quack")
popState()
popState()
pushState(IngameState.create(self, self.mapname))
pushState(CountdownState.create())
elseif id == "selectlevel" then
playSound("quack")
popState()
popState()
pushState(LevelSelectionState.create(self))
elseif id == "quit" then
playSound("quack")
popState()
popState()
end
end
function PauseGameState:isTransparent()
return true
end
return PauseGameState