/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 03:41:24 UTC
  • Revision ID: josh@9ix.org-20131214034124-vsekv7pyk6z5bvqf
basic delayed movement

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
   width = 16, height = 16,
4
4
   queue = deque.new(),
5
5
   onNew = function(self)
6
 
              for _ = 1, 2 do
7
 
                 local dirs = {'left', 'right', 'up', 'down', ''}
8
 
                 self.queue:push_right(dirs[math.random(1,5)])
 
6
              for _ = 1, 4 do
 
7
                 self.queue:push_right('')
9
8
              end
10
9
           end,
11
 
   onUpdate = function(self)
12
 
                 local keys = {the.keys:allJustPressed()}
13
 
                 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
28
 
                 end
29
 
              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
 
26
                  end
30
27
}
 
 
b'\\ No newline at end of file'