/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 04:59:50 UTC
  • Revision ID: josh@9ix.org-20130309045950-ufjp2txry3c0cc05
only jump when you're on the ground

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