I think I know the answer but I was hoping someone might be able to offer some insight as to a better way of producing this idea. What I have is a Castle demo gameloop(), with a sprite that moves randomly.
[lua] – sprite movement / solid detection
local spritewall = obstacleUniv(mrsprite, mrsprite.level, mrsprite.locX, mrsprite.locY)
if not spritewall then
– mrsprite:play()
npcPath = getNPCRandomPath() // up / down / left / right, randomly
if( not mrsprite.isMoving ) then
mte.moveSpriteTo( { sprite = mrsprite, locX = mrsprite.locX + npcPath[‘cords’][1], locY = mrpoo.locY + npcPath[‘cords’][2], time = spritemoveTime, easing = “linear” } )
mrsprite:setSequence(npcPath[‘direction’])
mrsprite:play()
end
– mte.moveSprite(mrsprite, aiPath1[aicounter][1], aiPath1[aicounter][2])
– npcAIPath1(mrsprite)
else
– print(‘pause the sprite’)
– print(mrsprite.sequence)
– mrsprite:setSequence(‘left’)
– mte.cancelSpriteMove(mrsprite) – maybe… but no
mrsprite:pause() – you’ve gone too far mrsprite!!!
– mrsprite:pause()
end[/lua]
I suppose I just need to check the tile property one tile ahead of the direction of the sprite movement in order to stop it before it walks too far. Is there a cleaner way to handle this logic? I understand this might be broad question but mainly seeking advice.
Thanks for any help / advice!