I'm making a game where a player moves across platforms of differing heights with different distances between each one. Since I want the game to be different every time, I've written code to automatically generate the "ice" that the player has passed to a position in front of the player.
float viewHeight = self.view.bounds.size.height;
float fViewHeightMinusIceHeight = viewHeight – 55.0f;
int iViewHeightMinusIceHeight = (int)fViewHeightMinusIceHeight;
if (ice.center.x >= (self.view.bounds.size.width + 8))
{
float y = random() %iViewHeightMinusIceHeight;
y = y + 22.5f;
float x = (random() % 20) – 8;
ice.center = CGPointMake(x,y);
}
This is only one of the objects. The same code is used for ice1, ice2, etc.
This generates the objects just fine. The first problem is that I would like to constrain the possibilities to only reasonable outcomes (e.g. no huge gaps), so that players can move from object to object.
The second problem is that sometimes the objects generate on top of one another.