/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-10 23:27:19 UTC
  • Revision ID: josh@9ix.org-20130610232719-52jhef5f8t57534p
indicators for where the planets are

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
              --the.rocks = Group:new()
98
98
              the.interface = Group:new()
99
99
              the.planets = Group:new()
 
100
              the.indicators = Group:new()
100
101
 
101
102
              the.bg = Tile:new{
102
103
                 image = 'data/stars3.png',
103
 
                 -- 1366x768 * 3
104
 
                 width = 4098,
105
 
                 height = 2304
 
104
                 width = 13660,
 
105
                 height = 7680
106
106
              }
107
107
              self:add(the.bg)
108
108
 
119
119
              --self:add(the.rockColliders)
120
120
              self:add(the.mirrors)
121
121
              --self:add(the.rocks)
 
122
              self:add(the.indicators)
122
123
              self:add(the.interface)
123
124
 
124
 
              local planet = Tile:new{
125
 
                 image = 'data/planet1.png',
126
 
                 x = math.random(the.app.width / 2,
127
 
                                 the.bg.width - the.app.width / 2),
128
 
                 y = math.random(the.app.height / 2,
129
 
                                 the.bg.height - the.app.height / 2),
130
 
              }
131
 
              the.planets:add(planet)
 
125
              for _ = 1, math.random(6) do
 
126
                 local planet = Tile:new{
 
127
                    image = 'data/planet1.png',
 
128
                    x = math.random(the.app.width / 2,
 
129
                                    the.bg.width - the.app.width / 2),
 
130
                    y = math.random(the.app.height / 2,
 
131
                                    the.bg.height - the.app.height / 2),
 
132
                    rotation = math.random() * math.pi
 
133
                 }
 
134
                 the.planets:add(planet)
 
135
 
 
136
                 planet.indicator = Tile:new{
 
137
                    image = 'data/planet1ind.png',
 
138
                 }
 
139
                 the.indicators:add(planet.indicator)
 
140
              end
132
141
 
133
142
              the.cursor = Cursor:new()
134
143
              self:add(the.cursor)
139
148
                 width = the.app.width,
140
149
                 --align = 'center',
141
150
                 font = 25}
142
 
              the.interface:add(the.score)
 
151
              --the.interface:add(the.score)
143
152
 
144
153
              local hs = the.storage.data.highScore
145
154
              local m = hs / 60
153
162
                 font = 25,
154
163
                 text = string.format('High Score: %d:%02d', m, s)
155
164
              }
156
 
              the.interface:add(the.highScore)
 
165
              --the.interface:add(the.highScore)
157
166
 
158
167
              the.over = Text:new{
159
168
                 y = the.app.height / 2,
217
226
 
218
227
                 the.bullets:collide(the.rockColliders)
219
228
 
 
229
                 -- this should really go somewhere else...
 
230
                 for _, planet in ipairs(the.planets.sprites) do
 
231
                    local indx, indy
 
232
                    local pvec = vector.new(
 
233
                       planet.x - the.player.x + planet.width / 2,
 
234
                       planet.y - the.player.y + planet.height / 2 )
 
235
 
 
236
                    -- TODO: is there a better way to specify the
 
237
                    -- screen rectangle?
 
238
                    if planet:intersects(the.player.x - the.app.width / 2,
 
239
                                         the.player.y - the.app.height / 2,
 
240
                                         the.app.width,
 
241
                                         the.app.height) then
 
242
                       -- planet is on the screen
 
243
                       planet.indicator.visible = false
 
244
                    else
 
245
                       planet.indicator.visible = true
 
246
 
 
247
                       if math.abs(pvec.x) / math.abs(pvec.y) > the.app.width / the.app.height then
 
248
                          indx = the.app.width / 2 * util.signOf(pvec.x) + 8
 
249
                          indy = the.app.width / 2 * pvec.y / math.abs(pvec.x)
 
250
                       else
 
251
                          indy = the.app.height / 2 * util.signOf(pvec.y) + 8
 
252
                          indx = the.app.height / 2 * pvec.x / math.abs(pvec.y)
 
253
                       end
 
254
 
 
255
                       planet.indicator.x = the.player.x + indx
 
256
                       planet.indicator.y = the.player.y + indy
 
257
                    end
 
258
                 end
 
259
 
220
260
                 -- for _, mirror in ipairs(the.mirrors.sprites) do
221
261
                 --    if not mirror.of then
222
262
                 --       print('mirror:' .. inspect(mirror))
284
324
                 self.console:watch('the.app.height', 'the.app.height')
285
325
                 self.console:watch('num mirrors', '#the.mirrors.sprites')
286
326
                 self.console:watch('num rocks', '#the.rocks.sprites')
 
327
                 self.console:watch('num planets', '#the.planets.sprites')
287
328
                 --self.console:watch('drawTook', 'the.drawTook')
288
329
 
289
330
                 -- back off that dark overlay a bit
291
332
              end
292
333
           end,
293
334
   onUpdate = function (self, dt)
294
 
                 if the.keys:justPressed('q') then
295
 
                    self.quit()
296
 
                 elseif the.keys:justPressed('return') then
297
 
                    if the.keys:pressed('alt') then
 
335
                 if not (DEBUG and the.console.visible) then
 
336
                    if the.keys:justPressed('q') then
 
337
                       self.quit()
 
338
                    elseif the.keys:justPressed('return') then
 
339
                       if the.keys:pressed('alt') then
 
340
                          love.graphics.toggleFullscreen()
 
341
                       else
 
342
                          self.view = GameView:new()
 
343
                       end
 
344
                    elseif the.keys:justPressed('f1') then
 
345
                       local ss = love.graphics.newScreenshot()
 
346
                       ss:encode('screenshot-' ..love.timer.getTime()..'.png')
 
347
                    elseif the.keys:justPressed('f11') then
298
348
                       love.graphics.toggleFullscreen()
299
 
                    else
300
 
                       self.view = GameView:new()
301
349
                    end
302
 
                 elseif the.keys:justPressed('f1') then
303
 
                    local ss = love.graphics.newScreenshot()
304
 
                    ss:encode('screenshot-' ..love.timer.getTime()..'.png')
305
 
                 elseif the.keys:justPressed('f11') then
306
 
                    love.graphics.toggleFullscreen()
307
350
                 end
308
351
              end,
309
352
   update = function (self, dt)