here is my code
public class bug3 extends Actor
{
private GreenfootImage image1 = new GreenfootImage ("bug3.png");
private GreenfootImage image2 = new GreenfootImage ("bug3flap.png");
private int speed = 2;
private int leftTurn = 100;
private int rightTurn = 480;
/**
* Move in the direction we are currently moving in. Turn if we reach a turning point.
*/
public void act()
{
setLocation ( getX() + speed, getY() );
Actor actor = getOneIntersectingObject(null);
if(actor != null) {
actor.setLocation ( actor.getX() + speed, actor.getY() );
}
if (atTurningPoint()) {
speed = -speed;
}
if (getImage().equals(image1)){
setImage (image2);
}
else{
setImage (image1);
}
}
/**
* Test if we are at one of the turning points.
*/
public boolean atTurningPoint()
{
return (getX() <= leftTurn || getX() >= rightTurn);
}
}
