/traderous

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

« back to all changes in this revision

Viewing changes to main.lua

  • Committer: Josh C
  • Date: 2013-05-18 00:09:56 UTC
  • Revision ID: josh@9ix.org-20130518000956-s9717aensfsq1b3c
fix double-removing sprites (and subsequent zombie mirror bullets).  
also lots of debug stuff.

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)
174
147
              self.gameStart = love.timer.getTime()
175
148
           end,
176
149
   onUpdate = function(self, dt)
177
 
                 if the.player.active and love.timer.getTime() > self.lastRock + self.rockInterval then
 
150
                 if love.timer.getTime() > self.lastRock + self.rockInterval then
178
151
                    local unseenRock = nil
179
152
                    while not unseenRock do
180
153
                       local rock = Rock:new{
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
 
                      self:updateScore()
 
189
                      local t = love.timer.getTime() - self.gameStart
 
190
                      local m = t / 60
 
191
                      local s = t % 60
 
192
 
 
193
                      the.score.text = string.format('Score: %d:%02d', m, s)
 
194
                      the.score.y = the.player.y - the.app.height / 2 + the.player.height
 
195
                      the.score.x = the.player.x - the.app.width / 2
220
196
                   end
 
197
 
 
198
                   the.highScore.y = the.player.y - the.app.height / 2 + the.player.height
 
199
                   the.highScore.x = the.player.x - the.app.width / 2
221
200
                end,
222
201
   draw = function (self, x, y)
223
202
             View.draw(self, x, y)
224
 
             --love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
225
 
          end,
226
 
   updateScore = function(self)
227
 
                    local t = love.timer.getTime() - self.gameStart
228
 
                    local m = t / 60
229
 
                    local s = t % 60
230
 
 
231
 
                    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
234
 
 
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
237
 
                 end
 
203
             love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
 
204
          end
238
205
}
239
206
 
240
207
MenuScreen = View:extend {
266
233
                 self.console:watch('the.app.width', 'the.app.width')
267
234
                 self.console:watch('the.app.height', 'the.app.height')
268
235
                 self.console:watch('num mirrors', '#the.mirrors.sprites')
269
 
                 self.console:watch('num rocks', '#the.rocks.sprites')
270
236
                 --self.console:watch('drawTook', 'the.drawTook')
271
237
 
272
238
                 -- back off that dark overlay a bit