/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,
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
147
123
                     end
148
124
 
149
125
                     if the.keys:justPressed('up') and
150
 
                      (self.onGround or the.console.visible or
 
126
                      (self.onGround or
151
127
                       (love.timer.getTime() - self.leftWallAt < .1) ) then
152
128
                        self.velocity.y = -400
153
129
                        self.jumping = true
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)
251
 
              end,
252
 
   draw = function (self, x, y)
253
 
             View.draw(self, x, y)
254
 
 
255
 
             love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
256
 
          end
 
228
              end
257
229
}
258
230
 
259
231
the.app = App:new {