/ld28

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

« back to all changes in this revision

Viewing changes to notplayer.lua

  • Committer: Josh C
  • Date: 2013-12-14 04:19:19 UTC
  • Revision ID: josh@9ix.org-20131214041919-p4awvb0gf7axmzc1
add a couple other clones that move randomly

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Clone = Tile:extend {
2
 
   image = 'data/player.png',
3
 
   onNew = function(self)
4
 
              self.direction = dirs[math.random(1,4)]
5
 
           end,
 
1
NotPlayer = Fill:extend {
 
2
   fill = {255,0,0},
 
3
   width = 16, height = 16,
 
4
   queue = deque.new(),
6
5
   doMove = function(self)
7
 
               if math.random(1,4) == 1 then -- change direction ~25%
8
 
                  self.direction = dirs[math.random(1,4)]
9
 
               end
 
6
               local dir = math.random(1,5)
10
7
 
11
 
               if self.direction == 'left' then
 
8
               if dir == 1 then
12
9
                  self.x = self.x - self.width
13
 
               elseif self.direction == 'right' then
 
10
               elseif dir == 2 then
14
11
                  self.x = self.x + self.width
15
 
               elseif self.direction == 'up' then
 
12
               elseif dir == 3 then
16
13
                  self.y = self.y - self.height
17
 
               elseif self.direction == 'down' then
 
14
               elseif dir == 4 then
18
15
                  self.y = self.y + self.height
19
16
               end
20
 
            end,
21
 
   onCollide = function(self, other)
22
 
                  if other ~= the.view.map then
23
 
                     --print('collision')
24
 
 
25
 
                     other:displaceDir(self,
26
 
                                       util.dirToXY(self.direction),
27
 
                                       - util.dirToPosNeg(self.direction))
28
 
                  end
29
 
 
30
 
                  if other == the.player then
31
 
                     self.image = 'data/player.png'
32
 
                  end
33
 
               end
 
17
            end
34
18
}
 
 
b'\\ No newline at end of file'