I'm making a game and i want to make it so that the enemy is on a platform and the enemy moves from one side of the platform to the other and back again. i also want it so the the enemy is continuously going back and forth.
// field int dir = 1; // movement code move(dir); // can be multiplied by a speed value // possible turning about code setLocation(getX(), getY()+2); Actor platform = getOneIntersectingObject(Platform.class); setLocation(getX(), getY()-2); int pX = platform.getX(); int pW = platform.getImage().getWidth(); if ((dir < 0 && pX-pW/2 >= getX()) || (dir > 0 && pX+pW/2 <= getX())) dir = -dir;
if ((dir < 0 && pX-pW/2 >= getX()) || (dir > 0 && pX+pW/2 <= getX()))
{
dir = -dir;
setImage("enemy" + dir + ".png")
//Replace .png with whatever format your image is saved as.
}
if ((dir < 0 && pX-pW/2 >= getX()) || (dir > 0 && pX+pW/2 <= getX()))
{
dir = -dir;
getImage().mirrorHorizontally();
}