Generating 2d Rivers

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. Here are a few more pictures:

About Nathaniel Inman

I'm a gamer, graphic designer, musician and software engineer. C++ and Javascript are my favorite two programming languages for which I develop exclusively in vim, tmux and zsh on Arch Linux.

Kansas City, Missouri http://www.theoestudio.com