/ld28

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

« back to all changes in this revision

Viewing changes to clone.lua

  • Committer: Josh C
  • Date: 2013-12-14 05:24:01 UTC
  • Revision ID: josh@9ix.org-20131214052401-8b2cma95lsvw7avq
rename NotPlayer to Clone cuz they're clones, and it's way too early 
for a class name like NotPlayer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
NotPlayer = Fill:extend {
 
1
local dirs = {'left', 'right', 'up', 'down'}
 
2
 
 
3
Clone = Fill:extend {
2
4
   fill = {255,0,0},
3
5
   width = 16, height = 16,
4
6
   queue = deque.new(),
 
7
   onNew = function(self)
 
8
              self.direction = dirs[math.random(1,4)]
 
9
           end,
5
10
   doMove = function(self)
6
 
               local dir = math.random(1,4)
 
11
               if math.random(1,4) == 1 then -- change direction ~25%
 
12
                  self.direction = dirs[math.random(1,4)]
 
13
               end
7
14
 
8
 
               if dir == 1 then
 
15
               if self.direction == 'left' then
9
16
                  self.x = self.x - self.width
10
 
               elseif dir == 2 then
 
17
               elseif self.direction == 'right' then
11
18
                  self.x = self.x + self.width
12
 
               elseif dir == 3 then
 
19
               elseif self.direction == 'up' then
13
20
                  self.y = self.y - self.height
14
 
               elseif dir == 4 then
 
21
               elseif self.direction == 'down' then
15
22
                  self.y = self.y + self.height
16
23
               end
17
24
            end