/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-05 16:38:21 UTC
  • Revision ID: josh@9ix.org-20130305163821-kw70drafjsh7329k
fix jitter caused by focus shift happening in the wrong order.  Looks 
like this is fixed in: 
https://bitbucket.org/klembot/zoetrope/commits/5e67ba491768caab0da8b9afc9954c072851e143

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
require 'zoetrope'
5
5
 
 
6
TERM_VEL = 400
 
7
 
6
8
Player = Tile:extend {
7
9
   image = 'data/player.png',
8
 
   onUpdate = function (self)
 
10
   onNew = function (self)
 
11
              self.velocity.y = 0
 
12
           end,
 
13
   onStartFrame = function (self)
 
14
                     -- this is all in startframe so it happens before
 
15
                     -- physics calc at beginning of update
 
16
 
9
17
                 self.velocity.x = 0
10
 
                 self.velocity.y = 0
 
18
                 -- TODO: this can be replaced with sprite.maxVel.y    
 
19
                 if self.velocity.y >= TERM_VEL then
 
20
                    self.velocity.y = TERM_VEL
 
21
                    self.acceleration.y = 0
 
22
                 else
 
23
                    self.acceleration.y = 800
 
24
                 end
11
25
 
12
26
                 if the.keys:pressed('left') then
13
27
                    self.velocity.x = -200
14
28
                 elseif the.keys:pressed('right') then
15
29
                    self.velocity.x = 200
16
30
                 end
 
31
 
 
32
                 if the.keys:justPressed('up') then
 
33
                    self.velocity.y = -400
 
34
                 end
 
35
              end,
 
36
   onUpdate = function (self)
 
37
                 -- this is called after physics, so this makes sense here
 
38
                 the.view.map:subdisplace(self)
17
39
              end
18
40
}
19
41
 
22
44
              self:loadLayers('data/map.lua')
23
45
              self.focus = the.player
24
46
              self:clampTo(self.map)
25
 
           end,
26
 
 
27
 
   onUpdate = function (self, dt)
28
 
                 self.map:subdisplace(the.player)
29
 
              end
 
47
           end
30
48
}
31
49
 
32
50
the.app = App:new {