I'm trying to make my actor called Enemy sequentially move to 3 points.
The X and Y coordinates are specified in my World called MyWorld by means of a matrix.
In the code of MyWorld I'm giving the public (int) variables ex1 (x-coordinate of enemy's target 1), ey2 (y-coordinate of enemy's target 1), ex2, ey2, ex3 and ey3.
Then in the actor Enemy I've got the private (int) variables called pointx1, pointy2 etc.
To set the pointx1 variables equal to the ex1 variables I've got the next code in the constructor of Enemy:
if (getWorld() != null)
{
pointx1 = ((MyWorld) getWorld()).getEX1();
pointy1 = ((MyWorld) getWorld()).ey1;
pointx2 = ((MyWorld) getWorld()).ex2;
pointy2 = ((MyWorld) getWorld()).ey2;
pointx3 = ((MyWorld) getWorld()).ex3;
pointy3 = ((MyWorld) getWorld()).ey3;
}
After that, in the act of the Enemy, I'm using the turnTowards method to move the Enemy sequentially to between the 3 points.
if (getX() == pointx1 && getY() == pointy1)
{
turnTowards(pointx2, pointy2);
passed1 = true;
}
else if (getX() == pointx2 && getY() == pointy2)
{
if( passed1 == true )
{
turnTowards(pointx3, pointy3);
}
else
{
turnTowards(pointx1, pointy1);
}
}
else if (getX() == pointx3 && getY() == pointy3)
{
turnTowards(pointx2, pointy2);
passed1 = false;
}
else
{
turnTowards(pointx1, pointy1);
}
But it doesn't work, the enemy keeps moving to the point while none of the points I placed are on that position.
By the way: the order of the points I placed are like this:
. point3 point 2
. point 1
