1
local dirs = {'left', 'right', 'up', 'down'}
1
3
Player = Fill:extend {
3
5
width = 16, height = 16,
5
7
onNew = function(self)
7
self.queue:push_right('')
9
self.queue:push_right(dirs[math.random(1,4)])
10
onStartFrame = function(self)
11
local keys = {the.keys:allJustPressed()}
12
for _, k in ipairs(keys) do
13
self.queue:push_right(k)
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
12
onUpdate = function(self)
13
local keys = {the.keys:allJustPressed()}
16
for _, dir in ipairs(dirs) do
17
if dir == keys[1] then
23
--print('key: ' .. keys[1])
24
self.queue:push_right(keys[1])
26
local inst = self.queue:pop_left()
27
if inst == 'left' then
28
self.x = self.x - self.width
29
elseif inst == 'right' then
30
self.x = self.x + self.width
31
elseif inst == 'up' then
32
self.y = self.y - self.height
33
elseif inst == 'down' then
34
self.y = self.y + self.height
b'\\ No newline at end of file'