/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-14 17:32:46 UTC
  • Revision ID: josh@9ix.org-20130514173246-rjq8assj79qbd6fn
explosions

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
              --    end
84
84
              -- end
85
85
 
86
 
              the.storage = Storage:new{filename = 'scores.lua'}
87
 
              the.storage:load()
88
 
              if not the.storage.data.highScore then
89
 
                 print('initializing storage')
90
 
                 the.storage.data = {highScore = 0}
91
 
              end
92
 
 
93
86
              the.rockColliders = Group:new()
94
87
              the.bullets = Group:new()
95
 
              the.mirrors = Group:new()
96
 
              the.rocks = Group:new()
97
88
 
98
89
              the.bg = Tile:new{
99
90
                 image = 'data/stars3.png',
109
100
 
110
101
              --self:add(Enemy:new{x=400, y=300})
111
102
 
112
 
              self:add(the.bullets)
113
 
              self:add(the.rockColliders)
114
 
              self:add(the.mirrors)
115
 
              self:add(the.rocks)
116
 
 
117
103
              the.cursor = Cursor:new()
118
104
              self:add(the.cursor)
119
105
 
120
 
              the.score = Text:new{
121
 
                 width = the.app.width,
122
 
                 align = 'center',
123
 
                 font = 25}
124
 
              self:add(the.score)
125
 
 
126
 
              local hs = the.storage.data.highScore
127
 
              local m = hs / 60
128
 
              local s = hs % 60
129
 
 
130
 
              the.highScore = Text:new{
131
 
                 width = the.app.width,
132
 
                 align = 'right',
133
 
                 font = 25,
134
 
                 text = string.format('High Score: %d:%02d', m, s)
135
 
              }
136
 
              self:add(the.highScore)
137
 
 
138
106
              love.mouse.setGrab(true)
139
107
              love.mouse.setVisible(false)
140
 
              love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
141
108
 
142
109
              --self:loadLayers('data/map.lua')
143
110
              self.focus = the.player
169
136
                        end
170
137
                    end
171
138
 
172
 
                    the.rocks:add(unseenRock)
 
139
                    self:add(unseenRock)
173
140
 
174
141
                    self.lastRock = love.timer.getTime()
175
142
                 end
176
143
 
177
144
                 the.bullets:collide(the.rockColliders)
178
145
              end,
179
 
   onEndFrame = function(self)
180
 
                   if the.player.active then
181
 
                      local t = love.timer.getTime() - self.gameStart
182
 
                      local m = t / 60
183
 
                      local s = t % 60
184
 
 
185
 
                      the.score.text = string.format('Score: %d:%02d', m, s)
186
 
                      the.score.y = the.player.y - the.app.height / 2 + the.player.height
187
 
                      the.score.x = the.player.x - the.app.width / 2
188
 
                   end
189
 
 
190
 
                   the.highScore.y = the.player.y - the.app.height / 2 + the.player.height
191
 
                   the.highScore.x = the.player.x - the.app.width / 2
192
 
                end,
193
146
   draw = function (self, x, y)
194
147
             View.draw(self, x, y)
195
148
             love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)