1
\$\begingroup\$

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):

enter image description here

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?

\$\endgroup\$
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – Philipp Apr 8 '16 at 20:12
  • \$\begingroup\$ Alrighty will try to do this approach thanks for your advice! \$\endgroup\$ – NeptaliD Apr 8 '16 at 20:40
3
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Engineer Apr 8 '16 at 21:39
  • \$\begingroup\$ Wow! this seems like a great implementation, i'm gonna try to do this right now thanks so much man! \$\endgroup\$ – NeptaliD Apr 8 '16 at 23:37
  • 1
    \$\begingroup\$ @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 \$\endgroup\$ – user3797758 Apr 10 '16 at 18:30
  • \$\begingroup\$ Whoops! sorry about that \$\endgroup\$ – NeptaliD Apr 10 '16 at 23:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.