/ld28

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

« back to all changes in this revision

Viewing changes to player.lua

  • Committer: Josh C
  • Date: 2013-12-14 05:07:54 UTC
  • Revision ID: josh@9ix.org-20131214050754-qvx21hikbfl6e2m4
move clones a little more like players move

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
local dirs = {'left', 'right', 'up', 'down'}
 
2
 
1
3
Player = Fill:extend {
2
4
   fill = {255,0,0},
3
5
   width = 16, height = 16,
4
6
   queue = deque.new(),
5
7
   onNew = function(self)
6
8
              for _ = 1, 2 do
7
 
                 local dirs = {'left', 'right', 'up', 'down', ''}
8
 
                 self.queue:push_right(dirs[math.random(1,5)])
 
9
                 self.queue:push_right(dirs[math.random(1,4)])
9
10
              end
10
11
           end,
11
12
   onUpdate = function(self)
12
13
                 local keys = {the.keys:allJustPressed()}
13
14
                 if keys[1] then
14
 
                    self.queue:push_right(keys[1])
15
 
 
16
 
                    local inst = self.queue:pop_left()
17
 
                    if inst == 'left' then
18
 
                       self.x = self.x - self.width
19
 
                    elseif inst == 'right' then
20
 
                       self.x = self.x + self.width
21
 
                    elseif inst == 'up' then
22
 
                       self.y = self.y - self.height
23
 
                    elseif inst == 'down' then
24
 
                       self.y = self.y + self.height
25
 
                    end
26
 
 
27
 
                    self.moved = true
 
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
 
 
26
                       local inst = self.queue:pop_left()
 
27
                       if inst == 'left' then
 
28
                          self.x = self.x - self.width
 
29
                       elseif inst == 'right' then
 
30
                          self.x = self.x + self.width
 
31
                       elseif inst == 'up' then
 
32
                          self.y = self.y - self.height
 
33
                       elseif inst == 'down' then
 
34
                          self.y = self.y + self.height
 
35
                       end
 
36
 
 
37
                       self.moved = true
 
38
                    end
28
39
                 end
29
40
              end
30
41
}
 
 
b'\\ No newline at end of file'