/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
35
36
37
38
39
40
41
42
43
44
45
46
47
GoalPerson = Tile:extend {
   image = 'data/goal.png',
   onNew = function(self)
              self.direction = dirs[math.random(1,4)]
           end,
   doMove = function(self)
               if math.random(1,4) ~= 1 then -- take a step ~2/3
                  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
            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
                     if the.view.level == 1 or the.view.level ==2 then
                        the.player.active = false
                        the.view:fade({0,0,0}):andThen(function()
                          the.app.view = SlowView:new {
                             level = the.view.level + 1
                          }
                       end)
                     elseif the.view.level == 3 then
                        the.app.view = WinView:new()
                     else
                        error('where did you find another level?')
                     end
                  end
               end
}