/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',
118
119
              --self:add(the.rockColliders)
119
120
              self:add(the.mirrors)
120
121
              --self:add(the.rocks)
 
122
              self:add(the.indicators)
121
123
              self:add(the.interface)
122
124
 
123
125
              for _ = 1, math.random(6) do
130
132
                    rotation = math.random() * math.pi
131
133
                 }
132
134
                 the.planets:add(planet)
 
135
 
 
136
                 planet.indicator = Tile:new{
 
137
                    image = 'data/planet1ind.png',
 
138
                 }
 
139
                 the.indicators:add(planet.indicator)
133
140
              end
134
141
 
135
142
              the.cursor = Cursor:new()
141
148
                 width = the.app.width,
142
149
                 --align = 'center',
143
150
                 font = 25}
144
 
              the.interface:add(the.score)
 
151
              --the.interface:add(the.score)
145
152
 
146
153
              local hs = the.storage.data.highScore
147
154
              local m = hs / 60
155
162
                 font = 25,
156
163
                 text = string.format('High Score: %d:%02d', m, s)
157
164
              }
158
 
              the.interface:add(the.highScore)
 
165
              --the.interface:add(the.highScore)
159
166
 
160
167
              the.over = Text:new{
161
168
                 y = the.app.height / 2,
219
226
 
220
227
                 the.bullets:collide(the.rockColliders)
221
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
 
222
260
                 -- for _, mirror in ipairs(the.mirrors.sprites) do
223
261
                 --    if not mirror.of then
224
262
                 --       print('mirror:' .. inspect(mirror))