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

2013/6/30

How do I add randomly moving enemies which end the game on impact?

grace_lowton grace_lowton

2013/6/30

#
please help, new to greenfoot
Gevater_Tod4711 Gevater_Tod4711

2013/6/30

#
For random moving enemys you should use Greenfoot.getRandomNumber(int) which returns a random number between 0 and the number you used as parameter -1. To end the game when an enemy touches you you should use this:
if (getOneIntersectingObject(Enemy.class) != null) {
    Greenfoot.stop();
}
If you put this code in the actor you control the game will end when an enemy touches this actor. If your enemy class is named different than Enemy you have to use the classname of your enemy class instead of Enemy.class.
davemib123 davemib123

2013/6/30

#
Also check out this link: http://www.greenfoot.org/doc/tut-5
grace_lowton grace_lowton

2013/7/1

#
thankyouuu^_^
You need to login to post a reply.