I know what the problem is, the cars keep trying to run the code but they are not in the world so it returns an error, but I do not know how to fix it.
Could somebody help me?
public class Vehicle extends Actor
{
private int Speed = Greenfoot.getRandomNumber(5)+3;
public void act()
{
vehicleMove();
collide();
bottomOfScreen();
}
public void bottomOfScreen()
{
if(getY()>= getWorld().getHeight()-1){getWorld().removeObject(this);}
return;
}
public void collide()
{
Actor collided;
collided = getOneIntersectingObject(Vehicle.class);
if (collided != null){Greenfoot.playSound("Explosion.wav");getWorld().removeObject(this);}
return;
}
public void vehicleMove()
{
setLocation(getX(),getY()+Speed);
}
}
