/ld28

To get this branch, use:
bzr branch http://9ix.org/bzr/ld28

« back to all changes in this revision

Viewing changes to goal_person.lua

  • Committer: Josh C
  • Date: 2013-12-14 20:52:47 UTC
  • Revision ID: josh@9ix.org-20131214205247-f42dwe3rx00da9cr
player collide w/ map

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
GoalPerson = Tile:extend {
2
 
   image = 'data/goal.png',
3
 
   onNew = function(self)
4
 
              self.direction = dirs[math.random(1,4)]
5
 
           end,
6
 
   doMove = function(self)
7
 
               if math.random(1,4) ~= 1 then -- take a step ~2/3
8
 
                  if math.random(1,4) == 1 then -- change direction ~25%
9
 
                     self.direction = dirs[math.random(1,4)]
10
 
                  end
11
 
 
12
 
                  if self.direction == 'left' then
13
 
                     self.x = self.x - self.width
14
 
                  elseif self.direction == 'right' then
15
 
                     self.x = self.x + self.width
16
 
                  elseif self.direction == 'up' then
17
 
                     self.y = self.y - self.height
18
 
                  elseif self.direction == 'down' then
19
 
                     self.y = self.y + self.height
20
 
                  end
21
 
               end
22
 
            end,
23
 
   onCollide = function(self, other)
24
 
                  if other ~= the.view.map then
25
 
                     --print('collision')
26
 
 
27
 
                     other:displaceDir(self,
28
 
                                       util.dirToXY(self.direction),
29
 
                                       - util.dirToPosNeg(self.direction))
30
 
                  end
31
 
 
32
 
                  if other == the.player then
33
 
                     if the.view.level == 1 then
34
 
                        the.app.view = GameView:new{level = 2}
35
 
                     elseif the.view.level == 2 then
36
 
                        the.app.view = GameView:new{level = 3}
37
 
                     elseif the.view.level == 3 then
38
 
                        error('WIN!')
39
 
                     end
40
 
                  end
41
 
               end
42
 
}
 
 
b'\\ No newline at end of file'