So I made a zombie game where the zombies follow the Survivor(see below) but now I added the feature that zombies spawn and because of that the code has stopped working. So the question is how to make the Zombies equal X to make it work. Sorry for the bad desription.
Thanks for your suggestions.
int speed=2;
int offset=100;
public int objectnumber=18;
public void randomTurn()
{
speed=Greenfoot.getRandomNumber(13);
if(((Level1)getWorld()).numberOfObjects()==objectnumber){
if(getWorld().getObjects(Surviver.class).get(0).X<getX()){setLocation(getX()-speed,getY());}
if(getWorld().getObjects(Surviver.class).get(0).X>getX()){setLocation(getX()+speed,getY());}
if(getWorld().getObjects(Surviver.class).get(0).Y<getY()){setLocation(getX(),getY()-speed);}
if(getWorld().getObjects(Surviver.class).get(0).Y>getY()){setLocation(getX(),getY()+speed);}}
if(getOneObjectAtOffset(1,0,Zombie1.class)!=null){setLocation(getX()-offset,getY());}
if(getOneObjectAtOffset(-1,0,Zombie1.class)!=null){setLocation(getX()+offset,getY());}
if(getOneObjectAtOffset(0,1,Zombie1.class)!=null){setLocation(getX(),getY()-offset);}
if(getOneObjectAtOffset(0,-1,Zombie1.class)!=null){setLocation(getX(),getY()+offset);}
}
