This site requires JavaScript, please enable it in your browser!
Greenfoot back
Svek
Svek wrote ...

2014/4/16

How to make auto moving players?

Svek Svek

2014/4/16

#
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!
Rishav_Agarwal Rishav_Agarwal

2014/4/16

#
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 }
Rishav_Agarwal Rishav_Agarwal

2014/4/16

#
I think this might help you!!!
You need to login to post a reply.