/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 20:49:59 UTC
  • Revision ID: josh@9ix.org-20131214204959-sbwlos88we9pckgo
... add the map.  and the extra code to work w/ it.

Show diffs side-by-side

added added

removed removed

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