/ld28

To get this branch, use:
bzr branch http://9ix.org/bzr/ld28
4 by Josh C
more clones, no null movement
1
local dirs = {'left', 'right', 'up', 'down'}
2
2 by Josh C
basic delayed movement
3
Player = Fill:extend {
4
   fill = {255,0,0},
5
   width = 16, height = 16,
6
   queue = deque.new(),
7
   onNew = function(self)
3 by Josh C
add a couple other clones that move randomly
8
              for _ = 1, 2 do
4 by Josh C
more clones, no null movement
9
                 self.queue:push_right(dirs[math.random(1,4)])
2 by Josh C
basic delayed movement
10
              end
11
           end,
3 by Josh C
add a couple other clones that move randomly
12
   onUpdate = function(self)
13
                 local keys = {the.keys:allJustPressed()}
14
                 if keys[1] then
4 by Josh C
more clones, no null movement
15
                    local dirKey = false
16
                    for _, dir in ipairs(dirs) do
17
                       if dir == keys[1] then
18
                          dirKey = true
19
                       end
20
                    end
21
22
                    if dirKey then
23
                       --print('key: ' .. keys[1])
24
                       self.queue:push_right(keys[1])
25
12 by Josh C
player collide w/ map
26
                       self.direction = self.queue:pop_left()
27
                       if self.direction == 'left' then
4 by Josh C
more clones, no null movement
28
                          self.x = self.x - self.width
12 by Josh C
player collide w/ map
29
                       elseif self.direction == 'right' then
4 by Josh C
more clones, no null movement
30
                          self.x = self.x + self.width
12 by Josh C
player collide w/ map
31
                       elseif self.direction == 'up' then
4 by Josh C
more clones, no null movement
32
                          self.y = self.y - self.height
12 by Josh C
player collide w/ map
33
                       elseif self.direction == 'down' then
4 by Josh C
more clones, no null movement
34
                          self.y = self.y + self.height
35
                       end
36
37
                       self.moved = true
38
                    end
3 by Josh C
add a couple other clones that move randomly
39
                 end
12 by Josh C
player collide w/ map
40
              end,
41
   onCollide = function(self, other)
42
                  if other ~= the.view.map then
43
                     --print('collision')
44
45
                     other:displaceDir(self,
46
                                       util.dirToXY(self.direction),
47
                                       - util.dirToPosNeg(self.direction))
48
                  end
49
               end
2 by Josh C
basic delayed movement
50
}