How to generate tile patterns in one dimension, then in a second dimension?

I'm trying to do a 2D Game that tries to emulate the Crossy Road game logic with the Java's GUI programming environment as a college project.

I'm having issues designing the way the 'roads' are procedurally generated.

An example of game-play of Crossy Road can be found here, but to give a glimpse, here is a screenshot (taken from the Crossy Road Web site):

The game is based on an infinite, randomly generated level. I need to generate different kinds of patterns, for example:

• one street then 2-way street
• some small river with logs around them
• etc.

I don't know how I could generate at first the types of roads/roads groups that one should cross, then how I could generate the tiles for that road, and then eventually how to link these roads with the different mobile items on them (floating logs, vehicles, trains, etc.).

How could I do that?

• I would recommend you to go by this project in incremental steps. First create a small hardcoded level without obstacles. Then add stationary obstacles. Then add moving obstacles. Then make these obstacles spawn. When you got that to work properly, make that one level loop infinitely. Then think about how you can generate it procedurally at runtime instead of looping it. Apr 8, 2016 at 20:12
• Alrighty will try to do this approach thanks for your advice! Apr 8, 2016 at 20:40

Looks to me like it works like this:

You have different biomes: road, rail, river, grass+trees, etc. Randomise a sequence of these like:

road, river, road, grass, grass, river, rail, road, grass etc., ad nauseam.

Now each of these occupy a width range. It seems to me from the video that the maximum size of the range increases as you travel further on into the world. So in the beginning, maybe each biome can only be 1-3 tiles wide, but as we move further into the world, that might increase to 1-20, or more. So for the above array you might have widths:

2, 1, 3, 2, 4, 3, 1, 5, 6 and so on, tending to get larger on average as the max increases.

...So basically you are just creating arrays of biome type+width. Of course there is a little more to it like scattering trees and cars, but that's fairly trivial once you have the basic patterns working.

Test this using perhaps 6 plain colours to create a sequence of variable-width bands onscreen.

At first I thought there was more to it, but sometimes we see patterns where there aren't any. It's more likely to be purely a random set of biome types + ranges for each, as above.

And to answer your question about cars: If there is a road band, it either has cars coming from left or right - include this factor in your arrays when you generate them. Depending on that, you can spawn cars moving into screen from left or into screen from right, i.e. at the ends of that road band.

• P.S. I would say that for the sake of increasing difficulty, maybe only the difficult biomes like rail, road and river will increase in width. Perhaps the grass+trees should never get much wider. Apr 8, 2016 at 21:39
• Wow! this seems like a great implementation, i'm gonna try to do this right now thanks so much man! Apr 8, 2016 at 23:37
• @NeptaliD if this is the correct answer then please click the green tick, Everyone wants to get the credit they deserve :) And welcome to the site Apr 10, 2016 at 18:30
• Whoops! sorry about that Apr 10, 2016 at 23:02