/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-16 15:56:20 UTC
  • Revision ID: josh@9ix.org-20130316155620-q8dze43bqqilhtmu
profiling and analysis

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