/ld27

To get this branch, use:
bzr branch http://9ix.org/bzr/ld27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
local velLimit = 400
Player = Tile:extend{
   image = 'data/player.png',
   maxVelocity = {x=velLimit,y=velLimit},
   minVelocity = {x=-velLimit, y=-velLimit},
   onNew = function(self)
              self.collider = PlayerCollider:new()
              the.view:add(self.collider)
           end,
   onStartFrame = function(self)
                     if the.keys:pressed('left') then
                        self.velocity.x = -200 * the.activeMaze.moveMod
                     elseif the.keys:pressed('right') then
                        self.velocity.x = 200 * the.activeMaze.moveMod
                     else
                        self.velocity.x = 0
                     end

                     if the.keys:pressed('up') then
                        self.velocity.y = -200 * the.activeMaze.moveMod
                     elseif the.keys:pressed('down') then
                        self.velocity.y = 200 * the.activeMaze.moveMod
                     else
                        self.velocity.y = 0
                     end
                  end,
   onUpdate = function(self, dt)
                 self.collider.x = self.x + self.width / 2 * (1 - self.scale)
                 self.collider.y = self.y + self.height / 2 * (1 - self.scale)
              end,
}

PlayerCollider = Fill:extend{
   fill = {0,0,255},
   onUpdate = function(self, dt)
                 self.visible = DEBUG and the.console.visible
              end,
   onCollide = function(self, other)
                  local p = the.player

                  other:displace(self)
                  p.x = self.x - p.width / 2 * (1 - p.scale)
                  p.y = self.y - p.height / 2 * (1 - p.scale)
               end
}