I am writing a game in Java and it can be likened to the recently popular game Flappy Bird in the sense that the character moves up and down and the users touch and must avoid the obstacles.The obstacles are going to be asteroids of varying sizes. I want to spawn these in at a random y co-odinate and with a random size, and then have them move across the screen. The character must then avoid these.It cant be completely random however as that may result in an non-traversable path. Thus I thought it would be best to define a random safe path first and then fill in the surrounding area with these obstacles. Is this the best approach to solving this problem, and if so is there correct and efficient way of doing this?
Defining a random safe path for a game character
java;algorithms;random
This is a common problem in games programming. I know of two approaches, which I think of as Forwards and Backwards.Forwards means that you generate a game by adding random things (asteroids) using some heuristics, and then you check that it has any solution (within the order of difficulty required). You keep randomly adding and checking until it gets too hard to find another thing to add and still have a solution.Backwards means that you generate a solution with specific features (difficulty, score, special features, etc). Then you add obsctacle until there is no other solution, but your desired solution is still possible.I prefer Backwards. Note that most solutions will require hand tuning to get good gameplay, so you need a mixture of random and crafted features.