I am trying to use the following code to detect if an explosion is on top of a brick:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
* Write a description of class redexplosion here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class redexplosion extends explosion
{
int explosionTime = 100;
/**
* Act - do whatever the explosions wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
explosionTime--;
checkExplosion();
}
private void checkExplosion()
{
if(explosionTime == 0)
{
getWorld().removeObject(this);
}
Actor brick = getOneIntersectingObject(brick.class);
//if(brick != null)
//{
// getWorld().removeObject(brick);
//}
}
}
But it keeps giving me this error:
java.lang.IllegalStateException: The actor has not been inserted into a world so it has no location yet. You might want to look at the method addedToWorld on the Actor class.
at greenfoot.Actor.failIfNotInWorld(Actor.java:605)
at greenfoot.Actor.getOneIntersectingObject(Actor.java:750)
at redexplosion.checkExplosion(redexplosion.java:29)
at redexplosion.act(redexplosion.java:20)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:199)
at greenfoot.core.Simulation.run(Simulation.java:128)
I see examples like this all the time but this one has me stumped. The brick clas name is lowercase so it isn't caused by that - capitalizing actually gives me a class not found error.