so I have a 700x700 screen and I want to create an object (an asteroid) to travel from the left side of the screen to the right side. As soon as it gets out of screen, I want it to spawn back at a random Y ana do the same thing. So far, I have created the object to spawn at a random Y and travel to the right, however, between 0:100 pixels and 600:700 pixels, I have objects and I do not want my object to spawn and travel through those objects. I want the random Y to be between let's say 101 and 599.
if (centerX > width + 200) {
isTravelling = false;
centerX = -200;
centerY = (int)(Math.random());
}