Generate Platforms (Rectangles) Randomly

Hey everyone,

I’m trying to figure out how to generate platforms so that they would be set out in a way like this:

http://imgur.com/CVjDfts

Imagine a platformer where the player should be able to “run” and “jump” onto all of the platforms.

I’ve tried generating a random boolean every frame with a certain chance that it would be true, and if true, create a rectangle of random length (in a range of course), as the x-position increases across the map. This didn’t work because at times there were platforms really close together, and sometimes it would be impossible to get from one side of the map to another (platforms too far apart).

The

Could someone suggest an algorithm I could use? I need to know “when” and “where” to create a platform, and how to generate the positions and sizes.

Other info which may be relevant, I’m using Box2D, the player is a 2x2m box.

Thanks

Added image for clarity. Use the code given there, not the page url.

In short: the level generator has to be aware of the player physics, how high/far they can jump, etc.

Clarifying BurntPizza’s explanation:

The reachable platforms are those which are to the left of the apogee of the arc or left of the arc past the apogee. i.e. those platforms that are ORANGE. Unreachable plat forms are in PINK.

To illustrate a possible implementation, I have knocked up a simple platformer:

http://pastebin.com/jPqihGKY

Keys:
Left
Right
Up for jump

That was very useful, thank you very much!