/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-16 02:41:58 UTC
  • Revision ID: josh@9ix.org-20130516024158-d5jtkfvd2qw709xo
record high scores

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
 
86
93
              the.rockColliders = Group:new()
87
94
              the.bullets = Group:new()
 
95
              the.mirrors = Group:new()
 
96
              the.rocks = Group:new()
88
97
 
89
98
              the.bg = Tile:new{
90
99
                 image = 'data/stars3.png',
100
109
 
101
110
              --self:add(Enemy:new{x=400, y=300})
102
111
 
 
112
              self:add(the.bullets)
 
113
              self:add(the.rockColliders)
 
114
              self:add(the.mirrors)
 
115
              self:add(the.rocks)
 
116
 
103
117
              the.cursor = Cursor:new()
104
118
              self:add(the.cursor)
105
119
 
 
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
 
106
138
              love.mouse.setGrab(true)
107
139
              love.mouse.setVisible(false)
 
140
              love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
108
141
 
109
142
              --self:loadLayers('data/map.lua')
110
143
              self.focus = the.player
136
169
                        end
137
170
                    end
138
171
 
139
 
                    self:add(unseenRock)
 
172
                    the.rocks:add(unseenRock)
140
173
 
141
174
                    self.lastRock = love.timer.getTime()
142
175
                 end
143
176
 
144
177
                 the.bullets:collide(the.rockColliders)
145
178
              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,
146
193
   draw = function (self, x, y)
147
194
             View.draw(self, x, y)
148
195
             love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)