So I have a tower defense type game where you defend against Octopuses. I added some CamoOctopuses that when they are killed they spawn a regular Octopus in the same spot that they are in. However, if the CamoOctopus is moving left or up when it is hit, the Octopus that is spawned will move backwards instead of the direction it is supposed to be going.
Here is my code for the CamoOctopus' movement:
Here is code for the bullet that hits the CamoOctopus:
public void death()
{
Actor o = getOneIntersectingObject(CamoOctopus.class);
if (o!=null)
{
Money.money+=50;
getWorld().addObject(new Octopus(),o.getX(),o.getY());
getWorld().removeObject(o);
getWorld().removeObject(this);
}
}
And the octopus moves using the same code as the camoOctopus. Thanks!
public void followLine()
{
Color Blue = new Color(0,0,255,255);
if(getWorld().getColorAt(getX()+1, getY()).getRed() < 100&&getWorld().getColorAt(getX()+1, getY()).getGreen() < 100&& x !=-1)
{
//right
setLocation(getX() + 1,getY());
y = 0;
x = 1;
}
else if(getWorld().getColorAt(getX()-1, getY()).getRed() < 100&& getWorld().getColorAt(getX()-1, getY()).getGreen() < 100&& x !=1)
{
//left
setLocation(getX()-1, getY());
y = 0;
x = -1;
}
else if(getWorld().getColorAt(getX(), getY()+1).getRed() < 100&& getWorld().getColorAt(getX(), getY()+1).getGreen() < 100 &&y != -1)
{
//down
setLocation(getX(), getY()+1);
x = 0;
y = 1;
}
else if(getWorld().getColorAt(getX(), getY()-1).getRed() < 100&&getWorld().getColorAt(getX(), getY()-1).getGreen() < 100&&y !=1)
{
//up
setLocation(getX(), getY()-1);
x = 0;
y = -1;
}
}

