/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-11 00:15:54 UTC
  • Revision ID: josh@9ix.org-20130611001554-tkzp73ke16buhnuy
bring indicators a little closer from edge

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 - 10) * util.signOf(pvec.x) + 8
 
249
                          indy = (the.app.width / 2 - 10) * pvec.y / math.abs(pvec.x)
 
250
                       else
 
251
                          indy = (the.app.height / 2 - 10) * util.signOf(pvec.y) + 8
 
252
                          indx = (the.app.height / 2 - 10) * 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))
272
312
 
273
313
              self.view = GameView:new()
274
314
 
275
 
              -- should fail silently if it can't go to fullscreen...
276
 
              love.graphics.toggleFullscreen()
277
 
 
278
315
              if DEBUG then
279
316
                 self.console:watch('VERSION', 'VERSION')
280
317
                 self.console:watch('updateTook', 'the.updateTook')
284
321
                 self.console:watch('the.app.height', 'the.app.height')
285
322
                 self.console:watch('num mirrors', '#the.mirrors.sprites')
286
323
                 self.console:watch('num rocks', '#the.rocks.sprites')
 
324
                 self.console:watch('num planets', '#the.planets.sprites')
287
325
                 --self.console:watch('drawTook', 'the.drawTook')
288
326
 
289
327
                 -- back off that dark overlay a bit
291
329
              end
292
330
           end,
293
331
   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
 
332
                 if not (DEBUG and the.console.visible) then
 
333
                    if the.keys:justPressed('q') then
 
334
                       self.quit()
 
335
                    elseif the.keys:justPressed('return') then
 
336
                       if the.keys:pressed('alt') then
 
337
                          love.graphics.toggleFullscreen()
 
338
                       else
 
339
                          self.view = GameView:new()
 
340
                       end
 
341
                    elseif the.keys:justPressed('f1') then
 
342
                       local ss = love.graphics.newScreenshot()
 
343
                       ss:encode('screenshot-' ..love.timer.getTime()..'.png')
 
344
                    elseif the.keys:justPressed('f11') then
298
345
                       love.graphics.toggleFullscreen()
299
 
                    else
300
 
                       self.view = GameView:new()
301
346
                    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
347
                 end
308
348
              end,
309
349
   update = function (self, dt)
314
354
               end
315
355
            end
316
356
}
 
357
 
 
358
realRun = love.run
 
359
function love.run()
 
360
   -- should fail silently if it can't go to fullscreen...
 
361
   love.graphics.toggleFullscreen()
 
362
 
 
363
   realRun()
 
364
end
 
 
b'\\ No newline at end of file'