/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:
6
6
--inspect = require 'inspect'
7
7
require 'pepperprof'
8
8
 
9
 
util = {
10
 
   dim = function(dir)
11
 
      if dir == 'x' then
12
 
         return 'width'
13
 
      elseif dir == 'y' then
14
 
         return 'height'
15
 
      else
16
 
         print 'dir ??'
17
 
      end
18
 
   end
19
 
}
20
 
 
21
9
Player = Animation:extend {
22
10
   image = 'data/player.png',
23
11
   height = 32,
77
65
                  if minVel[dir] and vel[dir] < minVel[dir] then vel[dir] = minVel[dir] end
78
66
                  if maxVel[dir] and vel[dir] > maxVel[dir] then vel[dir] = maxVel[dir] end
79
67
 
80
 
                  -- ugly hack for falling through floor on really slow frames
81
 
                  if math.abs(vel[dir] * elapsed) > 32 then
82
 
                     print('skip')
83
 
                     return
84
 
                  end
85
 
 
86
68
                  if vel[dir] ~= 0 then self[dir] = self[dir] + vel[dir] * elapsed end
87
 
 
88
 
                  if self[dir] < 0 then self[dir] = 0 end
89
 
                  local edge = the.view.map[util.dim(dir)] -
90
 
                               the.player[util.dim(dir)]
91
 
                  -- TODO: take map position into account
92
 
                  if self[dir] > edge then self[dir] = edge end
93
69
               end,
94
70
   onStartFrame = function (self)
95
71
                     -- this is all in startframe so it happens before
216
192
      end
217
193
   else
218
194
      -- handle sprites
219
 
      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
220
203
 
221
204
      local negMove = (other[dir] - self[dir]) + other[dim]
222
205
      local posMove = (self[dir] + self[dim]) - other[dir]
232
215
   other[dir] = other[dir] + chg
233
216
end
234
217
 
235
 
function Sprite:update (elapsed)
236
 
   if self.onUpdate then self:onUpdate(elapsed) end
237
 
end
238
 
 
239
218
GameView = View:extend {
240
219
   onNew = function (self)
241
220
              self:loadLayers('data/map.lua')
244
222
              self:clampTo(self.map)
245
223
           end,
246
224
   onUpdate = function (self)
247
 
                 --print('drawTook: ', the.drawTook)
248
225
                 --print('tick')
249
226
                 --the.player:collide(self.map)
250
227
                 --self.map:collide(the.player)