1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
Player = Fill:extend {
fill = {255,0,0},
width = 16, height = 16,
queue = deque.new(),
onNew = function(self)
for _ = 1, 4 do
self.queue:push_right('')
end
end,
onStartFrame = function(self)
local keys = {the.keys:allJustPressed()}
for _, k in ipairs(keys) do
self.queue:push_right(k)
local inst = self.queue:pop_left()
if inst == 'left' then
self.x = self.x - self.width
elseif inst == 'right' then
self.x = self.x + self.width
elseif inst == 'up' then
self.y = self.y - self.height
elseif inst == 'down' then
self.y = self.y + self.height
end
end
end
}
|