/spacey

To get this branch, use:
bzr branch http://9ix.org/bzr/spacey

« 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:
2
2
DEBUG = true
3
3
 
4
4
require 'zoetrope'
5
 
--__ = require 'underscore'
6
5
vector = require 'vector'
7
6
 
8
7
require 'group'
15
14
require 'cursor'
16
15
require 'bullet'
17
16
require 'rock'
 
17
require 'boom'
18
18
 
19
19
util = {
20
20
   signOf = function(value)
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
              the.rockColliders = Group:new()
 
94
              the.bullets = Group:new()
 
95
              the.mirrors = Group:new()
 
96
              the.rocks = Group:new()
 
97
 
86
98
              the.bg = Tile:new{
87
99
                 image = 'data/stars3.png',
88
100
                 -- 1366x768 * 3
97
109
 
98
110
              --self:add(Enemy:new{x=400, y=300})
99
111
 
 
112
              self:add(the.bullets)
 
113
              self:add(the.rockColliders)
 
114
              self:add(the.mirrors)
 
115
              self:add(the.rocks)
 
116
 
100
117
              the.cursor = Cursor:new()
101
118
              self:add(the.cursor)
102
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
 
103
138
              love.mouse.setGrab(true)
104
139
              love.mouse.setVisible(false)
 
140
              love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
105
141
 
106
142
              --self:loadLayers('data/map.lua')
107
143
              self.focus = the.player
133
169
                        end
134
170
                    end
135
171
 
136
 
                    self:add(unseenRock)
 
172
                    the.rocks:add(unseenRock)
137
173
 
138
174
                    self.lastRock = love.timer.getTime()
139
175
                 end
 
176
 
 
177
                 the.bullets:collide(the.rockColliders)
140
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,
141
193
   draw = function (self, x, y)
142
194
             View.draw(self, x, y)
143
195
             love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)