/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 06:03:56 UTC
  • Revision ID: josh@9ix.org-20130309060356-qvi2yd0odhfr3e6t
try to track X collisions.  break out Sprite's physics in prep for 
overriding them completely.

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
 
30
34
                     self.velocity.x = 0
31
35
                     self.acceleration.y = 800
32
36
 
33
37
                     if the.keys:pressed('left') then
34
38
                        self.velocity.x = -200
35
 
                        if self:onGround() then self:play('walk') end
 
39
                        if self.onGround then self:play('walk') end
36
40
                     elseif the.keys:pressed('right') then
37
41
                        self.velocity.x = 200
38
 
                        if self:onGround() then self:play('walk') end
 
42
                        if self.onGround then self:play('walk') end
39
43
                     else
40
 
                        if self:onGround() then self:play('stand') end
 
44
                        if self.onGround then self:play('stand') end
41
45
                     end
42
46
 
43
 
                     if the.keys:justPressed('up') and self:onGround() then
 
47
                     if the.keys:justPressed('up') and self.onGround then
44
48
                        self.velocity.y = -400
45
49
                        self.jumping = true
46
 
                        self:play('jump')
47
50
                     end
48
51
                  end,
49
 
   onEndFrame = function (self)
50
 
                   --print(self.velocity.y)
 
52
   onUpdate = function (self)
 
53
                 -- needs to happen right before collision
 
54
                 self.onGround = false
51
55
                end,
52
56
   onCollide = function (self, other, xOverlap, yOverlap)
53
57
                  -- seriously, why does this even fire?
59
63
                  -- assumption: any other collision is with a solid map tile
60
64
                  if yOverlap > xOverlap then
61
65
                     other:displace(self)
 
66
 
 
67
                     if self.velocity.x > 0 then
 
68
                        self.onWall = 'right'
 
69
                     elseif self.velocity.x < 0 then
 
70
                        self.onWall = 'left'
 
71
                     else
 
72
                        print '??'
 
73
                     end
62
74
                  elseif xOverlap > yOverlap then
63
75
                     -- check if we've moved since collisions were generated
64
76
                     local xov, yov = self:overlap(other.x, other.y,
65
77
                                                   other.width, other.height)
66
78
                     if xov ~= 0 and yov ~= 0 then
 
79
                        --print('y collision')
 
80
                        if self.velocity.y > 0 then
 
81
                           self.onGround = true
 
82
                        end
 
83
 
67
84
                        self.velocity.y = 0
68
85
                        other:displace(self)
69
86
                        self.jumping = false
73
90
                  end
74
91
 
75
92
               end,
76
 
   onGround = function (self)
77
 
                 return (not self.jumping) and (not self.falling)
78
 
              end
79
93
}
80
94
 
81
95
GameView = View:extend {
95
109
   onRun = function (self)
96
110
              self.view = GameView:new()
97
111
              --print(inspect(_(the.app):keys()))
 
112
              self.console:watch('onGround', 'the.player.onGround')
 
113
              self.console:watch('onWall', 'the.player.onWall')
98
114
           end,
99
115
   onUpdate = function (self, dt)
100
 
                 -- TODO: make this not work if debug console is active
101
 
                 if the.keys:justPressed('escape') then
 
116
                 if the.keys:justPressed('escape') and 
 
117
                   not self.console.visible then
102
118
                    love.event.quit()
103
119
                 end
104
120
              end