/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-06-16 03:53:05 UTC
  • Revision ID: josh@9ix.org-20130616035305-33ca39wd4q3q4v13
bullets don't go through planets

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
require 'rock'
18
18
require 'boom'
19
19
require 'planet'
 
20
require 'trade_view'
20
21
 
21
22
util = {
22
23
   signOf = function(value)
191
192
              self.gameStart = love.timer.getTime()
192
193
           end,
193
194
   onUpdate = function(self, dt)
194
 
                 if false and the.player.active and love.timer.getTime() > self.lastRock + self.rockInterval then
195
 
                    local unseenRock = nil
196
 
                    while not unseenRock do
197
 
                       local rock = Rock:new{
198
 
                          x = math.random(the.app.width / 2,
199
 
                                          the.bg.width - the.app.width / 2),
200
 
                          y = math.random(the.app.height / 2,
201
 
                                          the.bg.height - the.app.height / 2),
202
 
                          velocity = {
203
 
                             x = math.random(-300, 300),
204
 
                             y = math.random(-300, 300),
205
 
                             rotation = math.random(-7, 7)
206
 
                          },
207
 
                          scale = math.random() + 0.5
208
 
                       }
209
 
 
210
 
                       local rockToPlayer = util.shortestVector(rock, the.player)
211
 
                       if math.abs(rockToPlayer.x) > the.app.width / 2 + rock.width * rock.scale and
212
 
                           math.abs(rockToPlayer.y) > the.app.height / 2 + rock.height * rock.scale then
213
 
                         unseenRock = rock
214
 
                        end
215
 
                    end
216
 
 
217
 
                    the.rocks:add(unseenRock)
218
 
 
219
 
                    self.lastRock = love.timer.getTime()
220
 
                 end
221
 
 
222
 
                 the.bullets:collide(the.rockColliders)
 
195
                 the.bullets:collide(the.planets)
223
196
 
224
197
                 -- this should really go somewhere else...
225
198
                 for _, planet in ipairs(the.planets.sprites) do
226
 
                    local indx, indy
227
 
                    local pvec = vector.new(
228
 
                       planet.x - the.player.x + planet.width / 2,
229
 
                       planet.y - the.player.y + planet.height / 2 )
230
 
 
231
 
                    -- TODO: is there a better way to specify the
232
 
                    -- screen rectangle?
233
 
                    if planet:intersects(the.player.x - the.app.width / 2,
234
 
                                         the.player.y - the.app.height / 2,
235
 
                                         the.app.width,
236
 
                                         the.app.height) then
237
 
                       -- planet is on the screen
238
 
                       planet.indicator.visible = false
239
 
                    else
240
 
                       planet.indicator.visible = true
241
 
 
242
 
                       if math.abs(pvec.x) / math.abs(pvec.y) > the.app.width / the.app.height then
243
 
                          indx = (the.app.width / 2 - 10) * util.signOf(pvec.x) + 8
244
 
                          indy = (the.app.width / 2 - 10) * pvec.y / math.abs(pvec.x)
245
 
                       else
246
 
                          indy = (the.app.height / 2 - 10) * util.signOf(pvec.y) + 8
247
 
                          indx = (the.app.height / 2 - 10) * pvec.x / math.abs(pvec.y)
248
 
                       end
249
 
 
250
 
                       planet.indicator.x = the.player.x + indx
251
 
                       planet.indicator.y = the.player.y + indy
252
 
                    end
253
199
                 end
254
200
 
255
201
                 -- for _, mirror in ipairs(the.mirrors.sprites) do