A game where you play as a seal to collect anchors and boats but have to avoid the fish. The program runs fun but when i hit a fish i get an error that pops up everytime. pls help
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:695)
at greenfoot.Actor.isTouching(Actor.java:956)
at Seal.act(Seal.java:59)
at greenfoot.core.Simulation.actActor(Simulation.java:594)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
/**
*
*/
public class Seal extends Actor
{
public int fishScore = 0;
public int time;
/**
*
*/
public void act()
{
if (Greenfoot.isKeyDown("s"))
{
setRotation(90);
move(2);
}
if (Greenfoot.isKeyDown("w"))
{
setRotation(270);
move(2);
}
if (Greenfoot.isKeyDown("a"))
{
setRotation(180);
move(2);
}
if (Greenfoot.isKeyDown("d"))
{
setRotation(0);
move(2);
}
if (isTouching(Boat.class))
{
Ocean ocean = (Ocean)getWorld();
ocean.addScore(20);
removeTouching(Boat.class);
}
if (isTouching(Anchor.class))
{
Ocean ocean = (Ocean)getWorld();
ocean.addScore(10);
removeTouching(Anchor.class);
}
if (isTouching(Fish1.class))
{
Greenfoot.stop();
getWorld().showText("Timer:" + (time - time), 450,30);
getWorld().showText("Game Over", 300,200);
getWorld().removeObjects(getWorld().getObjects(null));
}
if (isTouching(Fish2.class))
{
Greenfoot.stop();
getWorld().showText("Timer:" + (time - time), 450,30);
getWorld().showText("Game Over", 300,200);
getWorld().removeObjects(getWorld().getObjects(null));
}
if (isTouching(Fish3.class))
{
Greenfoot.stop();
getWorld().showText("Timer:" + (time - time), 450,30);
getWorld().showText("Game Over", 300,200);
getWorld().removeObjects(getWorld().getObjects(null));
}
}
}
