/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
78
64
                  if maxVel[dir] and vel[dir] > maxVel[dir] then vel[dir] = maxVel[dir] end
79
65
 
80
66
                  if vel[dir] ~= 0 then self[dir] = self[dir] + vel[dir] * elapsed end
81
 
 
82
 
                  if self[dir] < 0 then self[dir] = 0 end
83
 
                  local edge = the.view.map[util.dim(dir)] -
84
 
                               the.player[util.dim(dir)]
85
 
                  -- TODO: take map position into account
86
 
                  if self[dir] > edge then self[dir] = edge end
87
67
               end,
88
68
   onStartFrame = function (self)
89
69
                     -- this is all in startframe so it happens before
122
102
                     if the.keys:pressed('left') then
123
103
                        self.velocity.x = -200
124
104
                        if self.onGround then self:play('walk') end
125
 
                        if self.onWall == 'right' then
126
 
                           self.onWall = false
127
 
                           self.leftWallAt = love.timer.getTime()
128
 
                        end
 
105
                        if self.onWall == 'right' then self.onWall = false end
129
106
                     elseif the.keys:pressed('right') then
130
107
                        self.velocity.x = 200
131
108
                        if self.onGround then self:play('walk') end
132
 
                        if self.onWall == 'left' then
133
 
                           self.onWall = false
134
 
                           self.leftWallAt = love.timer.getTime()
135
 
                        end
 
109
                        if self.onWall == 'left' then self.onWall = false end
136
110
                     else
137
111
                        if not self.onWall then
138
112
                           if self.onGround then self:play('stand') end
140
114
                        end
141
115
                     end
142
116
 
143
 
                     if the.keys:justPressed('up') and
144
 
                      (self.onGround or the.console.visible or
145
 
                       (love.timer.getTime() - self.leftWallAt < .1) ) then
 
117
                     if the.keys:justPressed('up') and self.onGround then
146
118
                        self.velocity.y = -400
147
119
                        self.jumping = true
148
120
                     end
210
182
      end
211
183
   else
212
184
      -- handle sprites
213
 
      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
214
193
 
215
194
      local negMove = (other[dir] - self[dir]) + other[dim]
216
195
      local posMove = (self[dir] + self[dim]) - other[dir]
244
223
              self.view = GameView:new()
245
224
              self.console:watch('onGround', 'the.player.onGround')
246
225
              self.console:watch('onWall', 'the.player.onWall')
247
 
              self.console:watch('updateTook', 'the.updateTook')
248
 
              self.console:watch('drawTook', 'the.drawTook')
249
 
 
250
 
              --the.profiler = newProfiler('time', 2000)
251
 
              --the.profiler = newProfiler()
252
 
              --the.profiler:start()
253
226
           end,
254
227
   onUpdate = function (self, dt)
255
 
                 if the.keys:justPressed('escape') then
256
 
                    if the.profiler then
257
 
                       the.profiler:stop()
258
 
                       local outfile = io.open( "profile.txt", "w+" )
259
 
                       the.profiler:report( outfile )
260
 
                       outfile:close()
261
 
                    end
262
 
 
 
228
                 if the.keys:justPressed('escape') and 
 
229
                   not self.console.visible then
263
230
                    self.quit()
264
231
                 end
265
 
              end,
266
 
   update = function (self, dt)
267
 
               the.updateStart = love.timer.getMicroTime()
268
 
               App.update(self, dt)
269
 
               if the.updateStart then
270
 
                  the.updateTook = love.timer.getMicroTime() - the.updateStart
271
 
               end
272
 
            end
273
 
}
 
232
              end
 
233
}
 
 
b'\\ No newline at end of file'