/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-20 01:30:46 UTC
  • Revision ID: josh@9ix.org-20130320013046-da2g35k1jzxdihlz
fps indicator, maybe a new tile

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
 
9
21
Player = Animation:extend {
10
22
   image = 'data/player.png',
11
23
   height = 32,
65
77
                  if minVel[dir] and vel[dir] < minVel[dir] then vel[dir] = minVel[dir] end
66
78
                  if maxVel[dir] and vel[dir] > maxVel[dir] then vel[dir] = maxVel[dir] end
67
79
 
 
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
 
68
86
                  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
69
93
               end,
70
94
   onStartFrame = function (self)
71
95
                     -- this is all in startframe so it happens before
192
216
      end
193
217
   else
194
218
      -- handle sprites
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
 
219
      local dim = util.dim(dir)
203
220
 
204
221
      local negMove = (other[dir] - self[dir]) + other[dim]
205
222
      local posMove = (self[dir] + self[dim]) - other[dir]
215
232
   other[dir] = other[dir] + chg
216
233
end
217
234
 
 
235
-- don't use zoetrope physics
 
236
function Sprite:update (elapsed)
 
237
   if self.onUpdate then self:onUpdate(elapsed) end
 
238
end
 
239
 
218
240
GameView = View:extend {
219
241
   onNew = function (self)
220
242
              self:loadLayers('data/map.lua')
222
244
              self:clampTo(self.map)
223
245
           end,
224
246
   onUpdate = function (self)
 
247
                 --print('drawTook: ', the.drawTook)
225
248
                 --print('tick')
226
249
                 --the.player:collide(self.map)
227
250
                 --self.map:collide(the.player)
228
 
              end
 
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
229
257
}
230
258
 
231
259
the.app = App:new {