/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
Player = Fill:extend {
   fill = {255,0,0},
   width = 16, height = 16,
   queue = deque.new(),
   onNew = function(self)
              for _ = 1, 2 do
                 local dirs = {'left', 'right', 'up', 'down', ''}
                 self.queue:push_right(dirs[math.random(1,5)])
              end
           end,
   onUpdate = function(self)
                 local keys = {the.keys:allJustPressed()}
                 if keys[1] then
                    self.queue:push_right(keys[1])

                    local inst = self.queue:pop_left()
                    if inst == 'left' then
                       self.x = self.x - self.width
                    elseif inst == 'right' then
                       self.x = self.x + self.width
                    elseif inst == 'up' then
                       self.y = self.y - self.height
                    elseif inst == 'down' then
                       self.y = self.y + self.height
                    end

                    self.moved = true
                 end
              end
}