-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapper.lua
162 lines (143 loc) · 3.64 KB
/
wrapper.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
--[[
Squaricles
Copyright (C) 2017 ITR
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
]]--
require ".anitext"
require ".menu"
require ".options"
require ".highscores"
require ".stats"
require ".gameinfo"
local LOSE_WAIT_TOTAL = LOSE_ANIM_SPEED*LOSE_ANIM_END_WAIT+10
Wrapper = {}
function Wrapper:new(canvas, input)
local o = clone(self)
o.canvas = canvas
o.input = input
o.mainMenu = Menu:new(canvas, {
"New Game",
"Highscores",
"Stats",
"Options",
"Quit"
})
o.options = Options:new(canvas, input)
o.current = function(dt) o:executeMainMenu() end
o.drawing = function() o:drawMainMenu() end
return o
end
function Wrapper:draw()
if self.drawing then
self.drawing()
end
end
function Wrapper:update(dt)
if self.current then
self.current(dt)
end
end
function Wrapper:executeMainMenu()
actions = {
[1] = function() --New Game
self:startGame()
end,
[2] = function() -- Highscores
self:startHighScore()
end,
[3] = function() -- Stats
self:startStats()
end,
[4] = function() -- Options
self:startOptions()
end,
[5] = function() -- Quit
quit()
end,
}
local action = self.mainMenu:run(self.input)
if action > 0 then
actions[action]()
end
end
function Wrapper:drawMainMenu()
love.graphics.setCanvas(self.canvas)
love.graphics.clear(0,0,0,255)
self.mainMenu:draw()
love.graphics.setCanvas()
end
function Wrapper:startGame()
local gameCanvas =
love.graphics.newCanvas(600, 1000)
local game = Game:new(gameCanvas,self.input,self.options)
local gameInfoDisplayer = GameInfoDisplayer:new(game,self.options.mode)
self.current = function(dt)
game:update(dt)
gameInfoDisplayer:update(dt)
if game.lost and game.lostAnim >= LOSE_WAIT_TOTAL then
self:startHighScore({game.score,game.level})
end
end
self.drawing = function()
game:draw()
love.graphics.setCanvas(self.canvas)
gameInfoDisplayer:draw()
love.graphics.draw(gameCanvas,10,190)
love.graphics.setCanvas()
end
self.playing = true
end
function Wrapper:startOptions()
self.playing = false
self.current = function(dt)
if self.options:run() then
self.current = function(dt) self:executeMainMenu() end
self.drawing = function() self:drawMainMenu() end
end
end
self.drawing = function()
self.options:draw()
end
end
function Wrapper:startHighScore(score)
self.playing = false
if score then
HighscoreList:addScore(score,self.options.mode)
end
local displayer = HighscoreDisplayer:new(
self.input,
self.options.mode,
score
)
self.current = function(dt)
if displayer:run(dt) then
self.current = function(dt) self:executeMainMenu() end
self.drawing = function() self:drawMainMenu() end
end
end
self.drawing = function()
displayer:draw(self.canvas)
end
end
function Wrapper:startStats()
self.playing = false
local viewer = StatViewer:new(self.canvas,self.input)
self.current = function(dt)
if viewer:run(dt) then
self.current = function(dt) self:executeMainMenu() end
self.drawing = function() self:drawMainMenu() end
end
end
self.drawing = function()
viewer:draw()
end
end