/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-17 21:23:13 UTC
  • Revision ID: josh@9ix.org-20130317212313-gsmwb0yt9hxdjj68
hack to not fall through floor on long first tick, monkey patch to turn 
off zoetrope physics (reliably, without depending on patched zoetrope)

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
require 'zoetrope'
5
5
__ = require 'underscore'
6
6
--inspect = require 'inspect'
 
7
require 'pepperprof'
 
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
}
7
20
 
8
21
Player = Animation:extend {
9
22
   image = 'data/player.png',
64
77
                  if minVel[dir] and vel[dir] < minVel[dir] then vel[dir] = minVel[dir] end
65
78
                  if maxVel[dir] and vel[dir] > maxVel[dir] then vel[dir] = maxVel[dir] end
66
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
 
67
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
68
93
               end,
69
94
   onStartFrame = function (self)
70
95
                     -- this is all in startframe so it happens before
122
147
                     end
123
148
 
124
149
                     if the.keys:justPressed('up') and
125
 
                      (self.onGround or
 
150
                      (self.onGround or the.console.visible or
126
151
                       (love.timer.getTime() - self.leftWallAt < .1) ) then
127
152
                        self.velocity.y = -400
128
153
                        self.jumping = true
191
216
      end
192
217
   else
193
218
      -- handle sprites
194
 
      local dim
195
 
      if dir == 'x' then
196
 
         dim = 'width'
197
 
      elseif dir == 'y' then
198
 
         dim = 'height'
199
 
      else
200
 
         print 'dir ??'
201
 
      end
 
219
      local dim = util.dim(dir)
202
220
 
203
221
      local negMove = (other[dir] - self[dir]) + other[dim]
204
222
      local posMove = (self[dir] + self[dim]) - other[dir]
214
232
   other[dir] = other[dir] + chg
215
233
end
216
234
 
 
235
-- don't use zoetrope physics
 
236
function Sprite:update (elapsed)
 
237
   if self.onUpdate then self:onUpdate(elapsed) end
 
238
end
 
239
 
217
240
GameView = View:extend {
218
241
   onNew = function (self)
219
242
              self:loadLayers('data/map.lua')
221
244
              self:clampTo(self.map)
222
245
           end,
223
246
   onUpdate = function (self)
 
247
                 --print('drawTook: ', the.drawTook)
224
248
                 --print('tick')
225
249
                 --the.player:collide(self.map)
226
250
                 --self.map:collide(the.player)
232
256
              self.view = GameView:new()
233
257
              self.console:watch('onGround', 'the.player.onGround')
234
258
              self.console:watch('onWall', 'the.player.onWall')
 
259
              self.console:watch('updateTook', 'the.updateTook')
 
260
              self.console:watch('drawTook', 'the.drawTook')
 
261
 
 
262
              --the.profiler = newProfiler('time', 2000)
 
263
              --the.profiler = newProfiler()
 
264
              --the.profiler:start()
235
265
           end,
236
266
   onUpdate = function (self, dt)
237
 
                 if the.keys:justPressed('escape') and 
238
 
                   not self.console.visible then
 
267
                 if the.keys:justPressed('escape') then
 
268
                    if the.profiler then
 
269
                       the.profiler:stop()
 
270
                       local outfile = io.open( "profile.txt", "w+" )
 
271
                       the.profiler:report( outfile )
 
272
                       outfile:close()
 
273
                    end
 
274
 
239
275
                    self.quit()
240
276
                 end
241
 
              end
242
 
}
 
 
b'\\ No newline at end of file'
 
277
              end,
 
278
   update = function (self, dt)
 
279
               the.updateStart = love.timer.getMicroTime()
 
280
               App.update(self, dt)
 
281
               if the.updateStart then
 
282
                  the.updateTook = love.timer.getMicroTime() - the.updateStart
 
283
               end
 
284
            end
 
285
}