/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 15:56:20 UTC
  • Revision ID: josh@9ix.org-20130316155620-q8dze43bqqilhtmu
profiling and analysis

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,
78
66
                  if maxVel[dir] and vel[dir] > maxVel[dir] then vel[dir] = maxVel[dir] end
79
67
 
80
68
                  if vel[dir] ~= 0 then self[dir] = self[dir] + vel[dir] * elapsed end
81
 
 
82
 
                  if self[dir] < 0 then self[dir] = 0 end
83
 
                  local edge = the.view.map[util.dim(dir)] -
84
 
                               the.player[util.dim(dir)]
85
 
                  -- TODO: take map position into account
86
 
                  if self[dir] > edge then self[dir] = edge end
87
69
               end,
88
70
   onStartFrame = function (self)
89
71
                     -- this is all in startframe so it happens before
141
123
                     end
142
124
 
143
125
                     if the.keys:justPressed('up') and
144
 
                      (self.onGround or the.console.visible or
 
126
                      (self.onGround or
145
127
                       (love.timer.getTime() - self.leftWallAt < .1) ) then
146
128
                        self.velocity.y = -400
147
129
                        self.jumping = true
210
192
      end
211
193
   else
212
194
      -- handle sprites
213
 
      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
214
203
 
215
204
      local negMove = (other[dir] - self[dir]) + other[dim]
216
205
      local posMove = (self[dir] + self[dim]) - other[dir]