Jetpack Joyride: https://www.youtube.com/watch?v=3KENMuzsras
What's the best way to add constraints to obstacle spawning (algorithms) or how to design obstacle spawning to allow constraints?
More details and my understanding
I am trying to understand how to add constraints to a spawning algorithm and I'm using Jetpack Joyride as reference (although I don't mind a general answer, especially if you're not very familiar with the game). I am particularly interested in the electrical obstacles [see image], so I will only consider them from now on.
There is probably a list of such obstacles from which one is fetched and placed on the screen. But where and when you place them is extremely important. First, you want to make sure your obstacles are between some minimum height -the floor- and some maximum height -the ceiling-. Then you may also want some minimum distance between any two consecutive obstacles. Also you don't want to spawn them too often, otherwise the game becomes repetitive. Then clearly you want to avoid sequences of obstacles that are impossible to pass. Then in some moments obstacles tend to spawn closer to the ground than usual. And so on.
I have no idea how to integrate, design-wise, all these constraints into obstacle spawning. I could probably have a lot of if statements and flags that are checked for each new item fetched from the available obstacles pool, but if I have a great number of constraints, the code may become very messy. I don't how this is approached in general.