I'm trying to code the movement for my Alien actor, and they are gonna be placed at the top left of the screen, and when they encounter an edge, (the left and right boundaries, in my situation). Once the objects fulfill my Boolean condition, I want them to move down, turn, and move in the opposite direction of which they were traveling. (Fyi my world size is 600, 400, 1);
The first boolean seems to do its job correctly, with the exception of the objects image being upside down, but when the objects are on the left hand side of the screen, they don't move as I initially want them to. Any assistance would be greatly appreciated.
public class Aliens extends Actor
{
/**
* Act - do whatever the Aliens wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public Aliens()
{
GreenfootImage image = getImage();
image.scale(image.getWidth() - 10, image.getHeight()- 10);
setImage(image);
}
public void act()
{
if(Greenfoot.getRandomNumber(1000) < 3){
getWorld().addObject(new Rocket(), this.getX(), this.getY());
}
move(1);
if (getX() > 590) {
turn(90);
move(2);
turn(90);
}
if (getX() < 10) {
turn(-90);
move(2);
turn(-90);
}
}
}
