Hey im trying to make a space invaders look alike.
But i have no idea how to make an Enemy move automatically to the left edge and the right edge.
it also needs to go one step down. Pleas help!
Take a variable, movement (say) = 5(or speed at what you want your enemy to move).
if ( getX()-getImage()/2 == 0 || getX()+getImage()/2 == getWorld().getWidth()-1 ) // This is the condition for position of enemy at the edges...
{
// Now you simply need to change the direction
movement = -movement;
}
setLocation ( getX() + movement , getY() );
if ( //condition for your enemy to come down )
{
setLocation ( getX() , getY() + down ); // down is the pixels by which your enemy should come down
}