Generating 2d Rivers

Rivers are usually hard to generate for 2d top-down games like roguelikes. Nathaniel Inman walks through some techniques to make this generation easier.

Generating 2d Rivers

Rivers are really hard to generate for 2d top-down games for multiple reasons:

  • Rivers primarily form based on heightmaps which are hard to display in top-down
  • Displaying fluidity when working with sectors or grid-based rendering can be complicated, bresenham's line algorithm only goes so far to make things look smooth
  • naturally occurring mechanisms of nature have numerous factors in play that caused them to exist. Simulating all of these factors isn't reasonable.

I was able to make relatively decent 2d rivers using a few techniques.

  1. Started by having terminal points where rivers can start/stop. Primary start positions might be at the centers of each screen edge, or corners if more than 4 terminal points are preferable.
  2. Shuffle the terminal points and randomly choose two, this is the main river start and end points.
  3. Use a weighted drunken walker that slightly pulls towards the end terminal point walking from the start terminal point.
  4. The drunken walker can spark another river if there are more terminal points left which will start from the walkers current position.

Finally the map went through some additional curation to make it look pretty outside of just the rivers to add things like mountains, sand or other obstructions.