115 lines
3.8 KiB
Lua
115 lines
3.8 KiB
Lua
actors={
|
|
list={},
|
|
|
|
add=function(actor)
|
|
actor.dx,actor.dy=0,0
|
|
table.insert(actors.list, actor)
|
|
end,
|
|
|
|
remove=function(name)
|
|
for i,v in ipairs(actors.list) do
|
|
if v.name and v.name==name then
|
|
table.remove(actors.list,i)
|
|
return
|
|
end
|
|
end
|
|
end,
|
|
|
|
search=function(name)
|
|
for i,v in ipairs(actors.list) do
|
|
if v.name and v.name==name then
|
|
return v
|
|
end
|
|
end
|
|
end,
|
|
|
|
draw=function()
|
|
for i,v in ipairs(actors.list) do
|
|
local frame=((v.dx+v.dy)%2)*16
|
|
--print(v.o)
|
|
if v.o=='u' then
|
|
--print(v.dy>1.." "..frame)
|
|
sspr(v.gfx.x+frame,v.gfx.y+16,16,16,v.x*8-4+v.dx*2,v.y*8-12+v.dy*2,16,16,v.dy>1)
|
|
elseif v.o=='d' then
|
|
--print(-v.dy>1.." "..frame)
|
|
sspr(v.gfx.x+frame,v.gfx.y,16,16,v.x*8-4+v.dx*2,v.y*8-12+v.dy*2,16,16,-v.dy>2)
|
|
elseif v.o=='l' then
|
|
sspr(v.gfx.x+frame,v.gfx.y+32,16,16,v.x*8-4+v.dx*2,v.y*8-12+v.dy*2,16,16)
|
|
elseif v.o=='r' then
|
|
sspr(v.gfx.x+frame,v.gfx.y+32,16,16,v.x*8-4+v.dx*2,v.y*8-12+v.dy*2,16,16,true)
|
|
end
|
|
end
|
|
end,
|
|
|
|
update=function()
|
|
local needs_sorting=false
|
|
for i,v in ipairs(actors.list) do
|
|
if v.dx==0 and v.dy==0 then
|
|
if v.path then
|
|
if v.path.pos == #v.path.route then
|
|
local in_scene = not v.path.keys
|
|
v.path=nil
|
|
game.update()
|
|
if in_scene then scene.cont() end
|
|
v.keys=nil
|
|
if v.name == actors.hero then
|
|
local switch = switches.search(v.x,v.y)
|
|
if switch then switch.action() end
|
|
end
|
|
else
|
|
v.path.pos=v.path.pos+1
|
|
local step=string.sub(v.path.route,v.path.pos,v.path.pos)
|
|
if step=='u' then
|
|
v.o='u'
|
|
--check collision!
|
|
v.y=v.y-1
|
|
v.dy=4
|
|
needs_sorting=true
|
|
elseif step=='d' then
|
|
v.o='d'
|
|
--check collision!
|
|
v.y=v.y+1
|
|
v.dy=-4
|
|
needs_sorting=true
|
|
elseif step=='l' then
|
|
v.o='l'
|
|
--check collision!
|
|
v.x=v.x-1
|
|
v.dx=4
|
|
elseif step=='r' then
|
|
v.o='r'
|
|
--check collision!
|
|
v.x=v.x+1
|
|
v.dx=-4
|
|
elseif step=='q' then
|
|
v.o='u'
|
|
elseif step=='a' then
|
|
v.o='d'
|
|
elseif step=='o' then
|
|
v.o='l'
|
|
elseif step=='p' then
|
|
v.o='r'
|
|
end
|
|
end
|
|
end
|
|
end
|
|
if v.dx > 0 then
|
|
v.dx=v.dx-1
|
|
elseif v.dx < 0 then
|
|
v.dx=v.dx+1
|
|
elseif v.dy > 0 then
|
|
v.dy=v.dy-1
|
|
elseif v.dy < 0 then
|
|
v.dy=v.dy+1
|
|
end
|
|
end
|
|
if needs_sorting then
|
|
table.sort(actors.list, compare_actors)
|
|
end
|
|
end
|
|
|
|
}
|
|
function compare_actors(a,b)
|
|
return a.y < b.y
|
|
end
|