DEV Community

Rising Tail
Rising Tail

Posted on • Updated on

Devlog #1: Making a capable map generator

That's a screenshot of a randomly generated map in my game. Well, at least in its current state, which changes day by day. For now my primary concern is making it capable of doing what I want, so don't pay too much attention to the actual visuals.

Disclaimer: I'm using tilesets from another game to help visualize the generated map. It goes without saying that when the time comes, I will hire an artist to do proper custom tilesets.

2D map generation has been written about, discussed and shown in youtube tutorials so many times that I can hardly warrant another piece on the matter. Nonetheless, I am going to talk about how I approached it.

There are so many ways to do map generation and what I do is nothing extraordinary. It's just a matter of combining a few tried and tested techniques. Here's what I did.

Use noise to generate a heightmap

I use a simplex noise generator that I found in a gist just by googling. Don't bother implmenenting noise yourself from scratch, unless you're interested in that kind of thing.

The individual cells in the heightmap will typically contain a value ranging from -1 to 0 or 0 to 1. I find 0 to 1 easiest to work with.

Elevation (and moisture)

Elevation has been used since the beginning of time to determine the terrain type. Basically you decide what ranges should result in which tile types, or colors, or whatever fits your needs. In a tile based terrain you could have values 0 - 0.2 be water, 0.2 - 0.5 be grass, 0.5 - 0.8 be mountains and so on. The heightmap is just a tool to deliver the underlying data, what you do with the data is entirely up to you.

Mapping elevation to terrain will yield a pretty good result. You can improve it by including another heightmap for moisture. This is something I learned over at Amit's excellent article. I don't have a lot of biomes/terrain types, so I don't utilize moisture just yet.


I find that the results can look a bit "messy". To make terrain more smooth and natural looking, I isolate every biome (ocean, beach, plains etc) into a list of 1's and 0's. Then I run each list into a cellular automata function, resulting in a more smooth terrain. This SO question is one example of how someone uses CA to improve a map.

Mapping biomes to tiles

This is easy. I have a list of tiles, and looping through the list I simply check if the current x, y point is inside an ocean biome, grass biome and so on. I use that data to assign the actual sprite of the tile.

Add details

Flower fields, trees and all sorts of terrain features can be added using the exact same method. I create another heightmap for flowers. Then, in the step where biomes are mapped to tiles, I check if the current tile is one where flowers would normally grow. If yes, I check the value of that point in the flower heightmap. If it's above a certain threshold I add in the flower on that tile. I would call this method somewhat naive, but it works for now.

What's next?

Now that I know how to generate basic maps, I need to figure out how the world in this game should look like and what it should entail. I'm not sure forests and flower fields even fits the theme, so I added those mainly to see if it would work. The world I'm envisioning is a much more desolate and dystopian place with little to no vegetation. That will ultimately make it hard to make the maps look interesting and pleasing, but I will try.

How would you approach map generation? What would you do to make it look interesting?

Discussion (0)