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

2013/2/23

PROBLEM BOMB EXPLODE!

Prish950 Prish950

2013/2/23

#
i want that my player set 5 bombs ok i got this but now i need an explode method for all 5 bombs always i just cant hit just one bomb. public void explode() { getWorld().removeObjects(getNeighbours(1, false, Wall_1.class)); getWorld().removeObjects(getNeighbours(1, false, Bomber_1.class)); getWorld().removeObjects(getNeighbours(1, false, Bomber_2.class)); getWorld().removeObjects(getIntersectingObjects(Bomber_1.class)); getWorld().removeObjects(getIntersectingObjects(Bomber_2.class)); getWorld().removeObjects(getWorld().getObjects(Bomb.class)); } Please Help!
danpost danpost

2013/2/24

#
Remove the last line from the 'explode' method. Each bomb should be able to decide for itself when to explode. You probably already have a timer so when the elapsed time has expired, it will explode. If you have an Explosion class, detecting a neighbouring explosion could be a trigger to explode as well.
Prish950 Prish950

2013/2/24

#
we wrote it so that the play has to activate the bomb with the e key
public void act() 
    {
      if(Greenfoot.isKeyDown("e"))
      {
        explode();

        
      }
so that all bombs are exploding at the same time but when i delete the last line the Bomb stay on the map an dont disappear !
danpost danpost

2013/2/24

#
Prish950 wrote...
we wrote it so that the play has to activate the bomb with the e key
public void act() 
    {
      if(Greenfoot.isKeyDown("e"))
      {
        explode();

        
      }
so that all bombs are exploding at the same time but when i delete the last line the Bomb stay on the map an dont disappear !
That I was not aware of. Sorry (add that line back in if you have not already). But because each will be removing itself when exploding, that line should read: getWorld().removeObject(this); Move the code in the act method just provided to the world class and have the world class call explode on all bombs in the world.
// in world act method (or a method it calls)
if (Greenfoot.isKeyDown("e")) for (Object obj : getObjects(Bomb.class)) ((Bomb) obj).explode();
Prish950 Prish950

2013/2/24

#
java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. at greenfoot.Actor.failIfNotInWorld(Actor.java:663) at greenfoot.Actor.getNeighbours(Actor.java:829) at Bomb.explode(Bomb.java:25) at Schlachtfeld.act(Schlachtfeld.java:13) at greenfoot.core.Simulation.actWorld(Simulation.java:571) at greenfoot.core.Simulation.runOneLoop(Simulation.java:506) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) This is the message i get when i copied in the world class actor. The bombs both going away but the result explode is only by the first i set in the world. I hope you understand what i mean lg
danpost danpost

2013/2/24

#
danpost wrote...
Sorry (add that line back in if you have not already). But because each will be removing itself when exploding, that line should read: getWorld().removeObject(this);
If you did not do this step, that error will occur.
Prish950 Prish950

2013/2/24

#
hmm i did iht like you said right now but i get an syntax error. then i make it so: getWorld().removeObjects(this().getObjects(bomb.class)); and i get an error too i cant help me. thank you alot for helping :)
danpost danpost

2013/2/24

#
When you changed it to what I suggested (which is what is should be), what error message are you getting (copy/paste the whole error message to your post).
Prish950 Prish950

2013/2/24

#
required Java until collection ???
Prish950 Prish950

2013/2/24

#
method removeObjects in class greenfoot.World annot be applied to given types; required java util collections found: Bomb reason:actual argument Bomb cannot be converted to java.util.collection by method invocation conversion The Operator that you use here cannot be used for the type of veluethat are you are using it for You are either using thhe wrong type here or the wrong operator
danpost danpost

2013/2/24

#
Please show your world class code for the 'act' method (and, if you are calling a method from there to check for exploding bomb trigger, that method, as well).
danpost danpost

2013/2/24

#
NVM, you did not remove the 's' to turn 'removeObjects' into 'removeObject'.
Prish950 Prish950

2013/2/24

#
IT WORKS THANK YOU SO MUCH
You need to login to post a reply.