/spacey

To get this branch, use:
bzr branch http://9ix.org/bzr/spacey

« back to all changes in this revision

Viewing changes to main.lua

  • Committer: Josh C
  • Date: 2013-05-20 16:51:19 UTC
  • Revision ID: josh@9ix.org-20130520165119-mkjh7d9408e6ig0u
extract updating score.  update score again when you calc high score - 
should mitigate a bug I saw happen when thor played that put final score 
+ high score out of sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
              the.bullets = Group:new()
96
96
              the.mirrors = Group:new()
97
97
              the.rocks = Group:new()
98
 
              the.interface = Group:new()
99
98
 
100
99
              the.bg = Tile:new{
101
100
                 image = 'data/stars3.png',
115
114
              self:add(the.rockColliders)
116
115
              self:add(the.mirrors)
117
116
              self:add(the.rocks)
118
 
              self:add(the.interface)
119
117
 
120
118
              the.cursor = Cursor:new()
121
119
              self:add(the.cursor)
122
120
 
123
121
              the.score = Text:new{
124
 
                 x = 8,
125
 
                 y = 8,
126
122
                 width = the.app.width,
127
 
                 --align = 'center',
 
123
                 align = 'center',
128
124
                 font = 25}
129
 
              the.interface:add(the.score)
 
125
              self:add(the.score)
130
126
 
131
127
              local hs = the.storage.data.highScore
132
128
              local m = hs / 60
133
129
              local s = hs % 60
134
130
 
135
131
              the.highScore = Text:new{
136
 
                 x = -8,
137
 
                 y = 8,
138
132
                 width = the.app.width,
139
133
                 align = 'right',
140
134
                 font = 25,
141
135
                 text = string.format('High Score: %d:%02d', m, s)
142
136
              }
143
 
              the.interface:add(the.highScore)
144
 
 
145
 
              the.over = Text:new{
146
 
                 y = the.app.height / 2,
147
 
                 width = the.app.width,
148
 
                 align = 'center',
149
 
                 font = 25,
150
 
                 text = "Game Over",
151
 
                 visible = false
152
 
              }
153
 
              the.interface:add(the.over)
154
 
 
155
 
 
156
 
              the.instructions = Text:new{
157
 
                 y = the.app.height / 2 + 32,
158
 
                 width = the.app.width,
159
 
                 align = 'center',
160
 
                 font = 12,
161
 
                 text = "Press Enter to start a new game\nPress Q to quit",
162
 
                 visible = false
163
 
              }
164
 
              the.interface:add(the.instructions)
 
137
              self:add(the.highScore)
165
138
 
166
139
              love.mouse.setGrab(true)
167
140
              love.mouse.setVisible(false)
212
185
                 -- end
213
186
              end,
214
187
   onEndFrame = function(self)
215
 
                   the.interface.translate.x = the.player.x - the.app.width / 2 + the.player.width / 2
216
 
                   the.interface.translate.y = the.player.y - the.app.height / 2 + the.player.height / 2
217
 
 
218
188
                   if the.player.active then
219
189
                      self:updateScore()
220
190
                   end
221
191
                end,
222
192
   draw = function (self, x, y)
223
193
             View.draw(self, x, y)
224
 
             --love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
 
194
             love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
225
195
          end,
226
196
   updateScore = function(self)
227
197
                    local t = love.timer.getTime() - self.gameStart
229
199
                    local s = t % 60
230
200
 
231
201
                    the.score.text = string.format('Score: %d:%02d', m, s)
232
 
                    --the.score.y = the.player.y - the.app.height / 2 + the.player.height
233
 
                    --the.score.x = the.player.x - the.app.width / 2 + the.player.width
 
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
234
204
 
235
 
                    --the.highScore.y = the.player.y - the.app.height / 2 + the.player.height
236
 
                    --the.highScore.x = the.player.x - the.app.width / 2
 
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
237
207
                 end
238
208
}
239
209