I make a space game and I need to have random asteroids spawning on margins and all of them fly randomly.Pls I need help!
int rand = Greenfoot.getRandomNumber(2*(getWidth()+getHeight())-4);
int x = 0, y = 0;
if (rand < getWidth()*2)
{
x = rand%getWidth();
y = (rand/getWidth())*(getHeight()-1);
}
else
{
y = (rand-2*getWidth())%(getHeight()-1)+1;
x = ((rand-2*getWidth())/(getHeight()-1))*(getWidth()-1);
}