I have a platform flash game which includes a level with just two backgrounds which are flipped side by side so that a looping background effect is created. In this I have to include Obstacles. Basically, when I designed the level, that was neat and good. But now I want to make the obstacles come randomly . Another factor is that since the player character in the platformer always keeps on running, if two obstacles come almost close together, it results in an impossible condition to win the game. So i need to avoid that too, without losing the factor of making the player think that the game is random.
|
What you are basically talking about is Procedural Content Generation. Roughly, you want to use a randomizing algorithm to make a "map" of upcoming content, and then run a check over that map to look for problems like "This gap is too small and makes the level impossible." I found, of all things, a wiki dedicated to the topic, which also has some code samples: http://pcg.wikidot.com/ You might also check out the roguelike development resources here: http://roguebasin.roguelikedevelopment.org/index.php?title=Roguelike_Dev_FAQ The techniques applied to roguelikes can usually apply to most 2D games. |
|||
|
|
|
Here is one way to do it. Set a minimum distance that things can spawn at, so things can always be winnable, but make this distance almost impossible to win. Have a difficulty variable that that starts out high for easy, and lowers as it gets harder. Set the position of the next object at the minimum distance + difficulty variable + a small random number. This will ensure that stuff spawns randomly, but it just has some rules to follow before it spawns. There are other more complex way to do it, but for what you are describing I think this is the best. |
|||
|
|
