56 lines
1.7 KiB
Lua
56 lines
1.7 KiB
Lua
actors={
|
|
list={},
|
|
|
|
add=function(actor)
|
|
actor.dx,actor.dy=0,0
|
|
table.insert(actors.list, actor)
|
|
end,
|
|
|
|
draw=function()
|
|
for i,v in ipairs(actors.list) do
|
|
sspr(v.gfx.x,v.gfx.y,16,16,v.x*8+v.dx,v.y*8+v.dy,16,16,v.o)
|
|
end
|
|
end,
|
|
|
|
update=function()
|
|
for i,v in ipairs(actors.list) do
|
|
if v.dx==0 and v.dy==0 then
|
|
if v.path then
|
|
v.path.pos=v.path.pos+1
|
|
if v.path.pos > #v.path.route then
|
|
v.path=nil
|
|
else
|
|
local step=string.sub(v.path.route,v.path.pos,v.path.pos)
|
|
if step=='u' then
|
|
--check collision!
|
|
v.y=v.y-1
|
|
v.dy=-8
|
|
elseif step=='d' then
|
|
--check collision!
|
|
v.y=v.y+1
|
|
v.dy=8
|
|
elseif step=='l' then
|
|
--check collision!
|
|
v.x=v.x-1
|
|
v.dx=-8
|
|
elseif step=='r' then
|
|
--check collision!
|
|
v.x=v.x+1
|
|
v.dx=8
|
|
end
|
|
end
|
|
end
|
|
else
|
|
if v.dx > 0 then
|
|
v.dx=v.dx-2
|
|
elseif v.dx < 0 then
|
|
v.dx=v.dx+2
|
|
elseif v.dy > 0 then
|
|
v.dy=v.dy-2
|
|
elseif v.dy < 0 then
|
|
v.dy=v.dy+2
|
|
end
|
|
end
|
|
end
|
|
end
|
|
} |