basicly i want to spawn obstacles always when there are less than 5 in the world. there are two ways of disappearing shoot them or when they fly to the end of the map but i cant figure out how i need to set the code that i dont get this error: java.lang.NullPointerException
at hinderniss.move(hinderniss.java:31)
at hinderniss.act(hinderniss.java:15)
this is the class:
import greenfoot.*;
public class hinderniss extends Actor
{
double hinderniss_SPEED = -3.0;
public void act()
{
move();
turnrandom();
spawnhinderniss();
}
public void move() {
setLocation ( (int) (getX() + hinderniss_SPEED), getY() );
if (getX() <= 30)
{
getWorld().removeObject(this);
hinderniss newHinderniss;
newHinderniss = new hinderniss();
int x = Greenfoot.getRandomNumber(1250) +1325;
int y = Greenfoot.getRandomNumber(600);
getWorld().addObject(newHinderniss, x, y);
}
}
public void turnrandom() {
if (Greenfoot.getRandomNumber(100) < 10)
{
turn(Greenfoot.getRandomNumber(90) - 45);
}
}
public void spawnhinderniss()
{
if(getWorld().getObjects(hinderniss.class).size()<5)
{
hinderniss newHinderniss;
newHinderniss = new hinderniss();
int x = Greenfoot.getRandomNumber(1250) +1325;
int y = Greenfoot.getRandomNumber(600);
getWorld().addObject(newHinderniss, x, y);
}
}
}
