/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:
4
4
require 'zoetrope'
5
5
__ = require 'underscore'
6
6
--inspect = require 'inspect'
7
 
require 'pepperprof'
8
7
 
9
8
Player = Animation:extend {
10
9
   image = 'data/player.png',
13
12
   sequences = {
14
13
      stand = { frames = { 1 }, fps = 1 },
15
14
      walk = { frames = { 2, 3 }, fps = 5 },
16
 
      jump = { frames = { 4 }, fps = 1 },
17
 
      climbLeft = { frames = { 5, 6 }, fps = 5 },
18
 
      climbRight = { frames = { 7, 8 }, fps = 5 }
 
15
      jump = { frames = { 4 }, fps = 1 }
19
16
   },
20
17
   collisions = {},
21
18
   onWall = false,
22
 
   leftWallAt = 0,
23
19
   onNew = function (self)
24
20
              self.velocity.y = 0
25
21
              self.maxVelocity.y = 400
80
76
                        self:play('jump')
81
77
                     end
82
78
 
 
79
                     self.velocity.x = 0
83
80
                     self.acceleration.y = 800
84
81
 
85
82
                     if self.onWall then
86
83
                        self.acceleration.y = 0
87
84
 
88
 
                        if self.onWall == 'right' then
89
 
                           self:play('climbRight')
90
 
                        elseif self.onWall == 'left' then
91
 
                           self:play('climbLeft')
92
 
                        end
93
 
 
94
85
                        if the.keys:pressed('up') then
95
86
                           self.velocity.y = -200
 
87
                           self:play('stand')
96
88
                        elseif the.keys:pressed('down') then
97
89
                           self.velocity.y = 200
 
90
                           self:play('stand')
98
91
                        else
99
92
                           self.velocity.y = 0
100
 
                           self:freeze(self.sequences[self.currentName].frames[1])
 
93
                           self:play('stand')
101
94
                        end
102
95
                     end
103
96
 
104
97
                     if the.keys:pressed('left') then
105
98
                        self.velocity.x = -200
106
99
                        if self.onGround then self:play('walk') end
107
 
                        if self.onWall == 'right' then
108
 
                           self.onWall = false
109
 
                           self.leftWallAt = love.timer.getTime()
110
 
                        end
 
100
                        if self.onWall == 'right' then self.onWall = false end
 
101
                        if self.onWall == 'right' then self.onWall = false end
111
102
                     elseif the.keys:pressed('right') then
112
103
                        self.velocity.x = 200
113
104
                        if self.onGround then self:play('walk') end
114
 
                        if self.onWall == 'left' then
115
 
                           self.onWall = false
116
 
                           self.leftWallAt = love.timer.getTime()
117
 
                        end
 
105
                        if self.onWall == 'left' then self.onWall = false end
118
106
                     else
119
 
                        if not self.onWall then
120
 
                           if self.onGround then self:play('stand') end
121
 
                           self.velocity.x = 0
122
 
                        end
 
107
                        if self.onGround then self:play('stand') end
123
108
                     end
124
109
 
125
 
                     if the.keys:justPressed('up') and
126
 
                      (self.onGround or
127
 
                       (love.timer.getTime() - self.leftWallAt < .1) ) then
 
110
                     if the.keys:justPressed('up') and self.onGround then
128
111
                        self.velocity.y = -400
129
112
                        self.jumping = true
130
113
                     end
136
119
               self:collide(the.view.map)
137
120
 
138
121
               -- handle X collisions
139
 
               self.onWall = false
140
122
               for _, col in ipairs(self.collisions) do
141
123
                  col.other:displaceDir(self, 'x')
142
124
                  if self.velocity.x > 0 then
233
215
              self.view = GameView:new()
234
216
              self.console:watch('onGround', 'the.player.onGround')
235
217
              self.console:watch('onWall', 'the.player.onWall')
236
 
              self.console:watch('updateTook', 'the.updateTook')
237
 
              self.console:watch('drawTook', 'the.drawTook')
238
 
 
239
 
              --the.profiler = newProfiler('time', 2000)
240
 
              --the.profiler = newProfiler()
241
 
              --the.profiler:start()
242
218
           end,
243
219
   onUpdate = function (self, dt)
244
 
                 if the.keys:justPressed('escape') then
245
 
                    if the.profiler then
246
 
                       the.profiler:stop()
247
 
                       local outfile = io.open( "profile.txt", "w+" )
248
 
                       the.profiler:report( outfile )
249
 
                       outfile:close()
250
 
                    end
251
 
 
 
220
                 if the.keys:justPressed('escape') and 
 
221
                   not self.console.visible then
252
222
                    self.quit()
253
223
                 end
254
 
              end,
255
 
   update = function (self, dt)
256
 
               the.updateStart = love.timer.getMicroTime()
257
 
               App.update(self, dt)
258
 
               if the.updateStart then
259
 
                  the.updateTook = love.timer.getMicroTime() - the.updateStart
260
 
               end
261
 
            end
262
 
}
 
224
              end
 
225
}
 
 
b'\\ No newline at end of file'