/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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Player = Tile:extend{
   image = 'data/player.png',
   onNew = function(self)
              self.collider = PlayerCollider:new{x=self.x, y=self.y}
              the.view:add(self.collider)
           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},
   collisions = {},
   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,
   update = function(self, elapsed)
               self.visible = DEBUG and the.console.visible

               self:doPhysics('x', elapsed)
               if not (DEBUG and the.console.visible) then
                  self:collide(the.activeMaze)
               end

               -- handle X collisions
               for _, col in ipairs(self.collisions) do
                  col.other:displaceDir(self, 'x')
               end

               self:doPhysics('y', elapsed)
               if not (DEBUG and the.console.visible) then
                  self:collide(the.activeMaze)
               end

               -- handle Y collisions
               for _, col in ipairs(self.collisions) do
                  col.other:displaceDir(self, 'y')
               end

               local p = the.player
               p.x = self.x - p.width / 2 * (1 - p.scale)
               p.y = self.y - p.height / 2 * (1 - p.scale)
            end,
   collide = function (self, ...)
                self.collisions = {}
                Fill.collide(self, ...)
             end,
   onCollide = function (self, other, xOverlap, yOverlap)
                  if other == the.activeMaze then return end

                  --print('collision')
                  --print(inspect(other))

                  table.insert(self.collisions, {other = other,
                                                 xOverlap = xOverlap,
                                                 yOverlap = yOverlap })
               end

}