/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-14 00:15:01 UTC
  • Revision ID: josh@9ix.org-20130514001501-z14e702ncp21s0yr
try to not spawn rocks where you can see them.  not working if screen 
crosses game boundaries.

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