Hi there!

I am losing my hair here with this stuff. I am trying to make the npc panel to move based on the current player panel position. It is a simple 2d game, with no entity, just panels. When the the panels colide, a new perspective is shown for the combat or some other interaction (like in that old conan game).

The npc either stays still or move to southwest doesn´t matter where is the player... here is part of the code relative to the problem:


function npcMove(var d)
{
var dir = d;
if (dir == 0)
{
npcX += 1;
npcY += 1;
}
if (dir == 1)
{
npcX += 1;
npcY -= 1;
}
if (dir == 2)
{
npcX -= 1;
npcY += 1;
}
if (dir == 3)
{
npcX -= 1;
npcY -= 1;
}
}


function aiScript()
{
//I´ll simplify the panels (I should be working right now)
// the X´s and Y´s are actually center_x and center_y of the panels
if (npcX < pX && npcY < pY) //go southeast
npcMove(0);
else if (npcX < pX && npcY > pY) //go northeast
npcMove(1);
else if (npcX > pX && npcY < pY) //go southwest
npcMove(2);
else if (npcX > pX && npcY > pY) //go northwest
npcMove(3);
}

function main()
{
//some initializations
while(1)
{
gameLoop();
//movement input for player panel and other stuff
aiScript();
wait(5);
}
}

So I need some help with this issue... thanks!