Ah, so that's the drawMe method. The problem is that you prevent the rocks from spawning on top of the spaceship, but after that, the drawMe method will change the location again.
protected void addedToWorld(World w)
{
xCoord=getX();
yCoord=getY();
drawMe();
while (!getObjectsInRange(100, Spaceship.class).isEmpty())
{
setLocation(Greenfoot.getRandomNumber(900), Greenfoot.getRandomNumber(900));
xCoord=getX();
yCoord=getY();
drawMe();
}
}public static void setCamLimits(double xMax,double yMax)
{
camMaxX=xMax;
camMaxY=yMax;
}public static void setCamLimits(double xMax,double yMax)
{
camMaxX=xMax;
camMaxY=yMax;
}ScrollingFixedObjects.setCamLimits(3200,3200);
ScrollingFixedObjects.setCamLimits(3200,3200);
public void placeRocks()
{
{
if(Greenfoot.getRandomNumber(20) == 1)
{
int x = Greenfoot.getRandomNumber(4100);
int y = Greenfoot.getRandomNumber(4100);
addObject(new Rock(), x, y);
rock.setRotation(Greenfoot.getRandomNumber(260));
}
}
} public void placeRocks()
{
{
if(Greenfoot.getRandomNumber(20) == 1)
{
int x = Greenfoot.getRandomNumber(4100);
int y = Greenfoot.getRandomNumber(4100);
addObject(new Rock(), x, y);
rock.setRotation(Greenfoot.getRandomNumber(260));
}
}
}System.out.println("spawned a Rock object at ("+x"+", "+y")"); public void placeRocks()
{
{
if(Greenfoot.getRandomNumber(20) == 1)
{
int x = Greenfoot.getRandomNumber(4100);
int y = Greenfoot.getRandomNumber(4100);
addObject(new Rock(), x, y);
rock.setRotation(Greenfoot.getRandomNumber(260));
}
}
}System.out.println("spawned a Rock object at ("+x"+", "+y")"); public Spielfeld()
{
super(900, 900, 1,false);
ScrollingFixedObjects.setCamLimits(3200,3200);
Spaceship = new Spaceship(this);
AddShip();
prepareHitCounter();
FPS();
centerCamOnPlayer();
setPaintOrder(DeathScreen.class,ResetInfo.class,HitCounter.class,FPS.class,explosion.class,Rock.class, Spaceship.class, Cloud1.class, Cloud2.class, Border.class, Border2.class);
placeRocksBeginning();
placeRocks();
placeClouds();
placeBorders();
}