/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-15 01:54:31 UTC
  • Revision ID: josh@9ix.org-20130315015431-torvm0zhbk1rvkn3
wall jump

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