/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:
 
1
STRICT = true
 
2
DEBUG = true
 
3
 
 
4
require 'zoetrope'
 
5
 
 
6
TERM_VEL = 400
 
7
 
 
8
Player = Tile:extend {
 
9
   image = 'data/player.png',
 
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
 
 
17
                 self.velocity.x = 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
 
25
 
 
26
                 if the.keys:pressed('left') then
 
27
                    self.velocity.x = -200
 
28
                 elseif the.keys:pressed('right') then
 
29
                    self.velocity.x = 200
 
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)
 
39
              end
 
40
}
 
41
 
 
42
GameView = View:extend {
 
43
   onNew = function (self)
 
44
              self:loadLayers('data/map.lua')
 
45
              self.focus = the.player
 
46
              self:clampTo(self.map)
 
47
           end
 
48
}
 
49
 
 
50
the.app = App:new {
 
51
   onRun = function (self)
 
52
              self.view = GameView:new()
 
53
           end,
 
54
   onUpdate = function (self, dt)
 
55
                 if the.keys:justPressed('escape') then
 
56
                    love.event.quit()
 
57
                 end
 
58
              end
 
59
}
 
 
b'\\ No newline at end of file'