/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 15:08:32 UTC
  • Revision ID: josh@9ix.org-20130312150832-ue1q4xuq4weypqc2
fairly major overhaul of collision handling to track whether we're on a 
wall.  also monkey patch Sprite to displace on only one axis

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