In my game there are ships moving from left to right while randomly spawning, now i want the ships to drop oil on a random X number. the code that i made for that is
private int getRandomNumber(int start, int end)
{
int normal = Greenfoot.getRandomNumber(end-start+1);
return normal+start;
}
int randomX = getRandomNumber(50,750);
if(getWorld() != null && getX() == randomX)
{
getWorld().addObject(new Oil(), getX(), getY());
}
Everything works fine but not every boat drops an oil.
any help would be appreciated

