+ 1
How Do You Create Infinite Obstacles in a game using Java?
Iām creating a program in Java rather similar to Flappy Bird, (mainly using StdDraw) where thereās repetitive obstacle that you have get past (like the pipes in flappy bird). My question is, how do I make it so as the player moves along, more and more obstacles are generated?
2 Answers
+ 3
I am not a prodigy in Java, but my guess is to implement a loop that keeps looping infinitely with random results, results being the obstacles! š
+ 2
Depending on long long your processing loop takes, you could use timer events to insert the next obstacle for short loop times. For longer loop times, call a function every place it is needed for the hardest level. In the function, decide whether a obstacle should be generated. Say you want the easiest to be every 40 or so calls. Add a random adjust of +5 to -5 range and count until you reach it. Adjust until it feels right.