/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-09 05:02:20 UTC
  • Revision ID: josh@9ix.org-20130309050220-bd1ybunyhk8fhwyw
reapply jump animation after Y collision.  (there's a frame of no 
jumping no falling that I can't do anything about w/o doing better 
collision handling)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
                     if self.falling then self.jumping = false end
28
28
                     --print(self.jumping, self.falling)
29
29
 
30
 
                     if not self.onGround then
 
30
                     if not self:onGround() then
31
31
                        self:play('jump')
32
32
                     end
33
33
 
36
36
 
37
37
                     if the.keys:pressed('left') then
38
38
                        self.velocity.x = -200
39
 
                        if self.onGround then self:play('walk') end
 
39
                        if self:onGround() then self:play('walk') end
40
40
                     elseif the.keys:pressed('right') then
41
41
                        self.velocity.x = 200
42
 
                        if self.onGround then self:play('walk') end
 
42
                        if self:onGround() then self:play('walk') end
43
43
                     else
44
 
                        if self.onGround then self:play('stand') end
 
44
                        if self:onGround() then self:play('stand') end
45
45
                     end
46
46
 
47
 
                     if the.keys:justPressed('up') and self.onGround then
 
47
                     if the.keys:justPressed('up') and self:onGround() then
48
48
                        self.velocity.y = -400
49
49
                        self.jumping = true
50
50
                     end
51
51
                  end,
52
 
   onUpdate = function (self)
53
 
                 -- needs to happen right before collision
54
 
                 self.onGround = false
 
52
   onEndFrame = function (self)
 
53
                   --print(self.velocity.y)
55
54
                end,
56
55
   onCollide = function (self, other, xOverlap, yOverlap)
57
56
                  -- seriously, why does this even fire?
68
67
                     local xov, yov = self:overlap(other.x, other.y,
69
68
                                                   other.width, other.height)
70
69
                     if xov ~= 0 and yov ~= 0 then
71
 
                        --print('y collision')
72
 
                        if self.velocity.y > 0 then
73
 
                           self.onGround = true
74
 
                        end
75
 
 
76
70
                        self.velocity.y = 0
77
71
                        other:displace(self)
78
72
                        self.jumping = false
82
76
                  end
83
77
 
84
78
               end,
 
79
   onGround = function (self)
 
80
                 return (not self.jumping) and (not self.falling)
 
81
              end
85
82
}
86
83
 
87
84
GameView = View:extend {
101
98
   onRun = function (self)
102
99
              self.view = GameView:new()
103
100
              --print(inspect(_(the.app):keys()))
104
 
              self.console:watch('onGround', 'the.player.onGround')
105
101
           end,
106
102
   onUpdate = function (self, dt)
107
 
                 if the.keys:justPressed('escape') and 
108
 
                   not self.console.visible then
 
103
                 -- TODO: make this not work if debug console is active
 
104
                 if the.keys:justPressed('escape') then
109
105
                    love.event.quit()
110
106
                 end
111
107
              end