From bcc1e7f60e7f3092e7240c8bbad461bfd6f683b5 Mon Sep 17 00:00:00 2001 From: JailDoctor Date: Mon, 30 Jan 2023 16:16:15 +0100 Subject: [PATCH] - [WIP] Actors behaviour. Switching computer --- data/actors.lua | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/data/actors.lua b/data/actors.lua index 2c71e3b..19bd6e6 100644 --- a/data/actors.lua +++ b/data/actors.lua @@ -2,6 +2,7 @@ actors={ list={}, add=function(actor) + actor.dx,actor.dy=0,0 table.insert(actors.list, actor) end, @@ -12,6 +13,44 @@ actors={ 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 } \ No newline at end of file