/zoeplat

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

« back to all changes in this revision

Viewing changes to main.lua

  • Committer: Josh C
  • Date: 2013-03-16 19:10:33 UTC
  • Revision ID: josh@9ix.org-20130316191033-o1qwl2zy3ps020y2
buildĀ moreĀ level

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
STRICT = true
2
2
DEBUG = true
3
 
RECORD = true
4
 
PLAYBACK = false
5
3
 
6
4
require 'zoetrope'
7
5
__ = require 'underscore'
8
6
--inspect = require 'inspect'
9
7
require 'pepperprof'
10
8
 
11
 
util = {
12
 
   dim = function(dir)
13
 
      if dir == 'x' then
14
 
         return 'width'
15
 
      elseif dir == 'y' then
16
 
         return 'height'
17
 
      else
18
 
         if STRICT then error('dir '..dir) end
19
 
      end
20
 
   end
21
 
}
22
 
 
23
9
Player = Animation:extend {
24
10
   image = 'data/player.png',
25
11
   height = 32,
79
65
                  if minVel[dir] and vel[dir] < minVel[dir] then vel[dir] = minVel[dir] end
80
66
                  if maxVel[dir] and vel[dir] > maxVel[dir] then vel[dir] = maxVel[dir] end
81
67
 
82
 
                  -- ugly hack for falling through floor on really slow frames
83
 
                  if math.abs(vel[dir] * elapsed) > 32 then
84
 
                     print('skip')
85
 
                     return
86
 
                  end
87
 
 
88
68
                  if vel[dir] ~= 0 then self[dir] = self[dir] + vel[dir] * elapsed end
89
 
 
90
 
                  if self[dir] < 0 then self[dir] = 0 end
91
 
                  local edge = the.view.map[util.dim(dir)] -
92
 
                               the.player[util.dim(dir)]
93
 
                  -- TODO: take map position into account
94
 
                  if self[dir] > edge then self[dir] = edge end
95
69
               end,
96
70
   onStartFrame = function (self)
97
71
                     -- this is all in startframe so it happens before
218
192
      end
219
193
   else
220
194
      -- handle sprites
221
 
      local dim = util.dim(dir)
 
195
      local dim
 
196
      if dir == 'x' then
 
197
         dim = 'width'
 
198
      elseif dir == 'y' then
 
199
         dim = 'height'
 
200
      else
 
201
         print 'dir ??'
 
202
      end
222
203
 
223
204
      local negMove = (other[dir] - self[dir]) + other[dim]
224
205
      local posMove = (self[dir] + self[dim]) - other[dir]
234
215
   other[dir] = other[dir] + chg
235
216
end
236
217
 
237
 
function Sprite:update (elapsed)
238
 
   if self.onUpdate then self:onUpdate(elapsed) end
239
 
end
240
 
 
241
218
GameView = View:extend {
242
219
   onNew = function (self)
243
220
              self:loadLayers('data/map.lua')
244
221
              self.focus = the.player
245
222
              self:clampTo(self.map)
246
 
 
247
 
              the.recorder = Recorder:new{mousePosInterval = 9999}
248
 
              the.app.meta:add(the.recorder)
249
 
              if RECORD then
250
 
                 the.recorder:startRecording()
251
 
              elseif PLAYBACK then
252
 
                 local storage = Storage:new{filename = 'record.lua'}
253
 
                 storage:load()
254
 
                 --print(inspect(storage.data))
255
 
                 the.recorder.record = storage.data
256
 
                 the.recorder:startPlaying()
257
 
              end
258
223
           end,
259
224
   onUpdate = function (self)
260
 
                 --print('drawTook: ', the.drawTook)
261
225
                 --print('tick')
262
226
                 --the.player:collide(self.map)
263
227
                 --self.map:collide(the.player)
264
 
              end,
265
 
   -- draw = function (self, x, y)
266
 
   --           View.draw(self, x, y)
267
 
 
268
 
   --           love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
269
 
   --        end
 
228
              end
270
229
}
271
230
 
272
231
the.app = App:new {
277
235
              self.console:watch('onWall', 'the.player.onWall')
278
236
              self.console:watch('updateTook', 'the.updateTook')
279
237
              self.console:watch('drawTook', 'the.drawTook')
280
 
              self.console:watch('recorder state', 'the.recorder.state')
281
238
 
282
239
              --the.profiler = newProfiler('time', 2000)
283
240
              --the.profiler = newProfiler()
292
249
                       outfile:close()
293
250
                    end
294
251
 
295
 
                    if RECORD then
296
 
                       if not love.filesystem.remove('record.lua') then
297
 
                          error('could not remove record.lua')
298
 
                       end
299
 
                       local storage = Storage:new{
300
 
                          data = the.recorder.record,
301
 
                          filename = 'record.lua'
302
 
                       }
303
 
                       storage:save(false)
304
 
                       --print(inspect(the.recorder.record))
305
 
                    end
306
 
 
307
252
                    self.quit()
308
253
                 end
309
254
              end,