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

2020/2/23

Explosion

Hundmat Hundmat

2020/2/23

#
What is the best way to make several characters from the same class disappear? I spawn the "enemies" and then they run towards a barrel, this barrel explodes. After the explosion, only one of several enemies dies because the code I wrote only affect one. So what is the best way of killing several enemies that interact with an image width? This is the code I have now.
Enemy mon = (Enemy)getOneIntersectingObject(Enemy.class);
        if(mon != null && this != null && getWorld() != null && animationVaribleExplode>=4) {
            getWorld().removeObject(this);
            mon.health-=10;
            mon.hit(10);
        }
danpost danpost

2020/2/23

#
You could use getIntersectingObjects which returns a List object containing any and all intersecting actors of the given class. You would probably need to then use a for-each type loop structure to apply damage to each enemy individually.
Hundmat Hundmat

2020/2/24

#
Okey thank you :)
You need to login to post a reply.