/ld27

To get this branch, use:
bzr branch /bzr/ld27

« back to all changes in this revision

Viewing changes to player.lua

  • Committer: Josh C
  • Date: 2013-08-25 02:38:46 UTC
  • Revision ID: josh@9ix.org-20130825023846-wgea9oh4n0o16gct
separate collision box for player so it can scale

Show diffs side-by-side

added added

removed removed

3
3
   image = 'data/player.png',
4
4
   maxVelocity = {x=velLimit,y=velLimit},
5
5
   minVelocity = {x=-velLimit, y=-velLimit},
 
6
   onNew = function(self)
 
7
              self.collider = PlayerCollider:new()
 
8
              the.view:add(self.collider)
 
9
           end,
6
10
   onStartFrame = function(self)
7
11
                     if the.keys:pressed('left') then
8
12
                        self.velocity.x = -200 * the.activeMaze.moveMod
20
24
                        self.velocity.y = 0
21
25
                     end
22
26
                  end,
 
27
   onUpdate = function(self, dt)
 
28
                 self.collider.x = self.x + self.width / 2 * (1 - self.scale)
 
29
                 self.collider.y = self.y + self.height / 2 * (1 - self.scale)
 
30
              end,
 
31
}
 
32
 
 
33
PlayerCollider = Fill:extend{
 
34
   fill = {0,0,255},
 
35
   onUpdate = function(self, dt)
 
36
                 self.visible = DEBUG and the.console.visible
 
37
              end,
23
38
   onCollide = function(self, other)
 
39
                  local p = the.player
 
40
 
24
41
                  other:displace(self)
 
42
                  p.x = self.x - p.width / 2 * (1 - p.scale)
 
43
                  p.y = self.y - p.height / 2 * (1 - p.scale)
25
44
               end
26
45
}
 
 
'\\ No newline at end of file'