/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 03:05:42 UTC
  • Revision ID: josh@9ix.org-20131215030542-pneoyxj6rtm3c3hx
super hacky fix for passing through clones/goals

Show diffs side-by-side

added added

removed removed

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