/ld28

To get this branch, use:
bzr branch http://9ix.org/bzr/ld28
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
Clone = Tile:extend {
   image = 'data/player.png',
   onNew = function(self)
              self.direction = dirs[math.random(1,4)]
           end,
   doMove = function(self)
               if math.random(1,4) == 1 then -- change direction ~25%
                  self.direction = dirs[math.random(1,4)]
               end

               if self.direction == 'left' then
                  self.x = self.x - self.width
               elseif self.direction == 'right' then
                  self.x = self.x + self.width
               elseif self.direction == 'up' then
                  self.y = self.y - self.height
               elseif self.direction == 'down' then
                  self.y = self.y + self.height
               end
            end,
   onCollide = function(self, other)
                  if other ~= the.view.map then
                     --print('collision')

                     other:displaceDir(self,
                                       util.dirToXY(self.direction),
                                       - util.dirToPosNeg(self.direction))
                  end

                  if other == the.player then
                     self.image = 'data/player.png'
                  end
               end
}