/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-12 17:48:42 UTC
  • Revision ID: josh@9ix.org-20130312174842-co8zn0hy0v6u18qf
climbing animation

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',
31
18
   },
32
19
   collisions = {},
33
20
   onWall = false,
34
 
   leftWallAt = 0,
35
21
   onNew = function (self)
36
22
              self.velocity.y = 0
37
23
              self.maxVelocity.y = 400
77
63
                  if minVel[dir] and vel[dir] < minVel[dir] then vel[dir] = minVel[dir] end
78
64
                  if maxVel[dir] and vel[dir] > maxVel[dir] then vel[dir] = maxVel[dir] end
79
65
 
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
66
                  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
67
               end,
94
68
   onStartFrame = function (self)
95
69
                     -- this is all in startframe so it happens before
128
102
                     if the.keys:pressed('left') then
129
103
                        self.velocity.x = -200
130
104
                        if self.onGround then self:play('walk') end
131
 
                        if self.onWall == 'right' then
132
 
                           self.onWall = false
133
 
                           self.leftWallAt = love.timer.getTime()
134
 
                        end
 
105
                        if self.onWall == 'right' then self.onWall = false end
135
106
                     elseif the.keys:pressed('right') then
136
107
                        self.velocity.x = 200
137
108
                        if self.onGround then self:play('walk') end
138
 
                        if self.onWall == 'left' then
139
 
                           self.onWall = false
140
 
                           self.leftWallAt = love.timer.getTime()
141
 
                        end
 
109
                        if self.onWall == 'left' then self.onWall = false end
142
110
                     else
143
111
                        if not self.onWall then
144
112
                           if self.onGround then self:play('stand') end
146
114
                        end
147
115
                     end
148
116
 
149
 
                     if the.keys:justPressed('up') and
150
 
                      (self.onGround or the.console.visible or
151
 
                       (love.timer.getTime() - self.leftWallAt < .1) ) then
 
117
                     if the.keys:justPressed('up') and self.onGround then
152
118
                        self.velocity.y = -400
153
119
                        self.jumping = true
154
120
                     end
216
182
      end
217
183
   else
218
184
      -- handle sprites
219
 
      local dim = util.dim(dir)
 
185
      local dim
 
186
      if dir == 'x' then
 
187
         dim = 'width'
 
188
      elseif dir == 'y' then
 
189
         dim = 'height'
 
190
      else
 
191
         print 'dir ??'
 
192
      end
220
193
 
221
194
      local negMove = (other[dir] - self[dir]) + other[dim]
222
195
      local posMove = (self[dir] + self[dim]) - other[dir]
232
205
   other[dir] = other[dir] + chg
233
206
end
234
207
 
235
 
function Sprite:update (elapsed)
236
 
   if self.onUpdate then self:onUpdate(elapsed) end
237
 
end
238
 
 
239
208
GameView = View:extend {
240
209
   onNew = function (self)
241
210
              self:loadLayers('data/map.lua')
244
212
              self:clampTo(self.map)
245
213
           end,
246
214
   onUpdate = function (self)
247
 
                 --print('drawTook: ', the.drawTook)
248
215
                 --print('tick')
249
216
                 --the.player:collide(self.map)
250
217
                 --self.map:collide(the.player)
256
223
              self.view = GameView:new()
257
224
              self.console:watch('onGround', 'the.player.onGround')
258
225
              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()
265
226
           end,
266
227
   onUpdate = function (self, dt)
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
 
 
 
228
                 if the.keys:justPressed('escape') and 
 
229
                   not self.console.visible then
275
230
                    self.quit()
276
231
                 end
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
 
}
 
232
              end
 
233
}
 
 
b'\\ No newline at end of file'