/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:
12
12
   sequences = {
13
13
      stand = { frames = { 1 }, fps = 1 },
14
14
      walk = { frames = { 2, 3 }, fps = 5 },
15
 
      jump = { frames = { 4 }, fps = 1 }
 
15
      jump = { frames = { 4 }, fps = 1 },
 
16
      climbLeft = { frames = { 5, 6 }, fps = 5 },
 
17
      climbRight = { frames = { 7, 8 }, fps = 5 }
16
18
   },
17
19
   collisions = {},
18
20
   onWall = false,
 
21
   leftWallAt = 0,
19
22
   onNew = function (self)
20
23
              self.velocity.y = 0
21
24
              self.maxVelocity.y = 400
76
79
                        self:play('jump')
77
80
                     end
78
81
 
79
 
                     self.velocity.x = 0
80
82
                     self.acceleration.y = 800
81
83
 
82
84
                     if self.onWall then
83
85
                        self.acceleration.y = 0
84
86
 
 
87
                        if self.onWall == 'right' then
 
88
                           self:play('climbRight')
 
89
                        elseif self.onWall == 'left' then
 
90
                           self:play('climbLeft')
 
91
                        end
 
92
 
85
93
                        if the.keys:pressed('up') then
86
94
                           self.velocity.y = -200
87
 
                           self:play('stand')
88
95
                        elseif the.keys:pressed('down') then
89
96
                           self.velocity.y = 200
90
 
                           self:play('stand')
91
97
                        else
92
98
                           self.velocity.y = 0
93
 
                           self:play('stand')
 
99
                           self:freeze(self.sequences[self.currentName].frames[1])
94
100
                        end
95
101
                     end
96
102
 
97
103
                     if the.keys:pressed('left') then
98
104
                        self.velocity.x = -200
99
105
                        if self.onGround then self:play('walk') end
100
 
                        if self.onWall == 'right' then self.onWall = false end
101
 
                        if self.onWall == 'right' then self.onWall = false end
 
106
                        if self.onWall == 'right' then
 
107
                           self.onWall = false
 
108
                           self.leftWallAt = love.timer.getTime()
 
109
                        end
102
110
                     elseif the.keys:pressed('right') then
103
111
                        self.velocity.x = 200
104
112
                        if self.onGround then self:play('walk') end
105
 
                        if self.onWall == 'left' then self.onWall = false end
 
113
                        if self.onWall == 'left' then
 
114
                           self.onWall = false
 
115
                           self.leftWallAt = love.timer.getTime()
 
116
                        end
106
117
                     else
107
 
                        if self.onGround then self:play('stand') end
 
118
                        if not self.onWall then
 
119
                           if self.onGround then self:play('stand') end
 
120
                           self.velocity.x = 0
 
121
                        end
108
122
                     end
109
123
 
110
 
                     if the.keys:justPressed('up') and self.onGround then
 
124
                     if the.keys:justPressed('up') and
 
125
                      (self.onGround or
 
126
                       (love.timer.getTime() - self.leftWallAt < .1) ) then
111
127
                        self.velocity.y = -400
112
128
                        self.jumping = true
113
129
                     end
119
135
               self:collide(the.view.map)
120
136
 
121
137
               -- handle X collisions
 
138
               self.onWall = false
122
139
               for _, col in ipairs(self.collisions) do
123
140
                  col.other:displaceDir(self, 'x')
124
141
                  if self.velocity.x > 0 then