/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-15 02:20:51 UTC
  • Revision ID: josh@9ix.org-20131215022051-kyqldojzgu2xxcg8
moving goal, clones turning green...

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
local dirs = {'left', 'right', 'up', 'down'}
2
 
 
3
1
Player = Fill:extend {
4
2
   fill = {255,0,0},
5
3
   width = 16, height = 16,
6
4
   queue = deque.new(),
7
5
   onNew = function(self)
8
 
              for _ = 1, 2 do
 
6
              for _ = 1, math.random(1,3) do
9
7
                 self.queue:push_right(dirs[math.random(1,4)])
10
8
              end
11
9
           end,
23
21
                       --print('key: ' .. keys[1])
24
22
                       self.queue:push_right(keys[1])
25
23
 
26
 
                       local inst = self.queue:pop_left()
27
 
                       if inst == 'left' then
 
24
                       self.direction = self.queue:pop_left()
 
25
                       if self.direction == 'left' then
28
26
                          self.x = self.x - self.width
29
 
                       elseif inst == 'right' then
 
27
                       elseif self.direction == 'right' then
30
28
                          self.x = self.x + self.width
31
 
                       elseif inst == 'up' then
 
29
                       elseif self.direction == 'up' then
32
30
                          self.y = self.y - self.height
33
 
                       elseif inst == 'down' then
 
31
                       elseif self.direction == 'down' then
34
32
                          self.y = self.y + self.height
35
33
                       end
36
34
 
37
35
                       self.moved = true
38
36
                    end
39
37
                 end
40
 
              end
 
38
              end,
 
39
   onCollide = function(self, other)
 
40
                  if other ~= the.view.map then
 
41
                     --print('collision')
 
42
 
 
43
                     other:displaceDir(self,
 
44
                                       util.dirToXY(self.direction),
 
45
                                       - util.dirToPosNeg(self.direction))
 
46
                  end
 
47
               end
41
48
}
 
 
b'\\ No newline at end of file'