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

2012/12/19

Explosion

Pacplay Pacplay

2012/12/19

#
How would you make a rock blow up when a rocket ship touched it?
Gevater_Tod4711 Gevater_Tod4711

2012/12/20

#
In your rocket you have to check if it hits a rock and if you found one make it explode. To detect you should use code like this:
//in your rocket;
private boolean rockHit() {
    return !getWorld().getOneIntersectingObject(Rock.class).isEmpty();
}
To make your rock explode you could use the explosion from the luna landing scenario or just delete the object.
danpost danpost

2012/12/20

#
@Gevater_Tod4711, (1) 'getOneIntersectingObject' is an Actor class method (2) 'getOneIntersectingObject' returns an Object (not a list) Because of (1) above, you cannot use the method on a World object ('getWorld' returns a World object) Because of (2) above, you cannot use 'isEmpty()' on what it returns ('isEmpty' is a List class method) It should be
return getOneIntersectingObject(Rock.class) != null;
You need to login to post a reply.