87
the.storage = Storage:new{filename = 'scores.lua'}
89
if not the.storage.data.highScore then
90
print('initializing storage')
91
the.storage.data = {highScore = 0}
86
94
the.rockColliders = Group:new()
87
95
the.bullets = Group:new()
88
96
the.mirrors = Group:new()
113
121
the.score = Text:new{
114
122
width = the.app.width,
117
125
self:add(the.score)
127
local hs = the.storage.data.highScore
131
the.highScore = Text:new{
132
width = the.app.width,
135
text = string.format('High Score: %d:%02d', m, s)
137
self:add(the.highScore)
119
139
love.mouse.setGrab(true)
120
140
love.mouse.setVisible(false)
121
141
love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
127
147
self.gameStart = love.timer.getTime()
129
149
onUpdate = function(self, dt)
130
if love.timer.getTime() > self.lastRock + self.rockInterval then
150
if the.player.active and love.timer.getTime() > self.lastRock + self.rockInterval then
131
151
local unseenRock = nil
132
152
while not unseenRock do
133
153
local rock = Rock:new{
158
178
the.bullets:collide(the.rockColliders)
180
-- for _, mirror in ipairs(the.mirrors.sprites) do
181
-- if not mirror.of then
182
-- print('mirror:' .. inspect(mirror))
183
-- error('mirror OF NOTHING')
160
187
onEndFrame = function(self)
161
188
if the.player.active then
162
local t = love.timer.getTime() - self.gameStart
166
the.score.text = string.format('Score: %d:%02d', m, s)
167
the.score.y = the.player.y - the.app.height / 2 + the.player.height
168
the.score.x = the.player.x - the.app.width / 2
171
192
draw = function (self, x, y)
172
193
View.draw(self, x, y)
173
love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
194
--love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
196
updateScore = function(self)
197
local t = love.timer.getTime() - self.gameStart
201
the.score.text = string.format('Score: %d:%02d', m, s)
202
the.score.y = the.player.y - the.app.height / 2 + the.player.height
203
the.score.x = the.player.x - the.app.width / 2 + the.player.width
205
the.highScore.y = the.player.y - the.app.height / 2 + the.player.height
206
the.highScore.x = the.player.x - the.app.width / 2
177
210
MenuScreen = View:extend {
202
235
self.console:watch('the.player.y', 'the.player.y')
203
236
self.console:watch('the.app.width', 'the.app.width')
204
237
self.console:watch('the.app.height', 'the.app.height')
238
self.console:watch('num mirrors', '#the.mirrors.sprites')
239
self.console:watch('num rocks', '#the.rocks.sprites')
205
240
--self.console:watch('drawTook', 'the.drawTook')
207
242
-- back off that dark overlay a bit