/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 19:47:43 UTC
  • Revision ID: josh@9ix.org-20131215194743-ye0rbul4qruqau4g
title screen

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
              local delay = {0,1,2}
 
6
              for _ = 1, delay[the.view.level] do
 
7
                 self.queue:push_right(dirs[math.random(1,4)])
8
8
              end
9
9
           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
 
10
   onUpdate = function(self)
 
11
                 local keys = {the.keys:allJustPressed()}
 
12
                 if keys[1] then
 
13
                    local dirKey = false
 
14
                    for _, dir in ipairs(dirs) do
 
15
                       if dir == keys[1] then
 
16
                          dirKey = true
 
17
                       end
 
18
                    end
 
19
 
 
20
                    if dirKey then
 
21
                       --print('key: ' .. keys[1])
 
22
                       self.queue:push_right(keys[1])
 
23
 
 
24
                       self.direction = self.queue:pop_left()
 
25
                       if self.direction == 'left' then
 
26
                          self.x = self.x - self.width
 
27
                       elseif self.direction == 'right' then
 
28
                          self.x = self.x + self.width
 
29
                       elseif self.direction == 'up' then
 
30
                          self.y = self.y - self.height
 
31
                       elseif self.direction == 'down' then
 
32
                          self.y = self.y + self.height
 
33
                       end
 
34
 
 
35
                       self.moved = true
 
36
                    end
 
37
                 end
 
38
              end,
 
39
   onCollide = function(self, other)
 
40
                  if other ~= the.view.map and other ~= the.goalPerson then
 
41
                     --print('collision')
 
42
 
 
43
                     other:displaceDir(self,
 
44
                                       util.dirToXY(self.direction),
 
45
                                       - util.dirToPosNeg(self.direction))
26
46
                  end
 
47
               end
27
48
}
 
 
b'\\ No newline at end of file'