/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
31
32
33
34
35
36
37
38
39
40
41
local dirs = {'left', 'right', 'up', 'down'}

Player = Fill:extend {
   fill = {255,0,0},
   width = 16, height = 16,
   queue = deque.new(),
   onNew = function(self)
              for _ = 1, 2 do
                 self.queue:push_right(dirs[math.random(1,4)])
              end
           end,
   onUpdate = function(self)
                 local keys = {the.keys:allJustPressed()}
                 if keys[1] then
                    local dirKey = false
                    for _, dir in ipairs(dirs) do
                       if dir == keys[1] then
                          dirKey = true
                       end
                    end

                    if dirKey then
                       --print('key: ' .. keys[1])
                       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
              end
}