Creating a random 2d game world map, Part 3: Cities, caves and snow

I have been continuing my 2d game world generator (part 1, part2) and I wanted to show you my progress so far.

This time I added small stuff that was simple to implement and didn’t require any special programming.

World name

A world name tag.
Heloist

I now name my worlds. To do so I use the code described in this post. Right now, I show my world name in the upper left corner in white letters.

Snow

A snowy island.
A snowy island.

Nothing fancy here, the top ~7% of the map is covered with snow, with the last row having a 50% chance to be covered in snow.

I ignore mountain and water tiles and just replace the other types of tiles with a snow tile. As for forest tiles, I replace them with a snowy forest tile.

Caves

A remote mountain cave.
A remote mountain cave.

To implement caves I select a random number of tiles which fit the following criterion:

  • must be a mountain tile
  • must be on the edge of a non-mountain region
  • must not be next to another cave
  • must have at least 2 mountain neighbor tiles in a radius of 2 tiles
  • must have at least 2 non-mountain, non-water neighbor tiles in a radius of 2 tiles

Cities

A city next to a river.
A city next to a river.

For cities I use the same technique as for caves, picking out random tiles that fit some criterion.

The criterion are pretty much the same, but I also add the criteria that a city must be within 2 tiles of a water tile. Real world cities are usually built near fresh or sea water so this adds a touch of realism.

Results

Here are the results from a randomly generated world, the world of Norgele.

A world map with snow, cities and caves.
A world map with snow, cities and caves.

Future improvements

As for future improvements, the next step would be to add some roads to connect the different cities together. For this I have been thinking about using A* with each type of terrain having a different weight for how difficult such a terrain would be to cross.

5 thoughts on “Creating a random 2d game world map, Part 3: Cities, caves and snow

    1. It’s all open-source under the MIT license. You can find it here: https://github.com/gilles-leblanc/gameproject on GitHub. The code to create the overland maps is specifically under the “MapGenerator” directory.

      It’s in Ruby so you need to have Ruby installed on your computer. From the MapGenerator directory you should be able to do “ruby map_output.rb” to create and view a map (provided you have installed the dependencies specified in the readme file).

      There is some basic info in the readme file. Since I have never distributed the program there isn’t any packaged distribution or anything.

      If you have any questions or need any help with the source code I will be happy to help you.

  1. Hey,

    Nice work! My first map generator I took a similar path with both height and rain maps, but abandoned the approach after finding that for truly massive world generation the maps required too much time & memory to compute. Although ..they did look much better and are more cohesive.

    Which leads me to ask – how does this handle world spaces of more epic proportions – 1 million x 1 million for example? Have you done any work on generating a map given another map? Say that one wanted to generate a truly epic size map (by joining smaller maps together), or perhaps extend an existing one ..

    I’m trying to work out a more ‘divide and conquer’ recursive approach (the diamond / square approach looks promising http://danielbeard.wordpress.com/2010/08/07/terrain-generation-and-smoothing/) that has something closer to an o(n) complexity (one can dream).

    (Also any work on swamps?).

    I have a python (2.7) version of the second map gen approach (still non recursive sadly) if you want a copy. I’d offer you the recursive but I haven’t finished it yet 😛
    Seems only fair if you are offering code too 😀

    G.

    1. Hi,

      You’re right this algorithm is pretty slow. When I started working on this I didn’t know any better.

      I don’t need to handle worlds of epic sizes since the game I am using this for doesn’t require it. Since each pixel ends up being one square the player can occupy on the map, a 200×200 map ends up being really big once you start to navigate it.

      So for my purposes, even though it is slow, the algorithm is working fine. Specially since it’s well tailored to simulating volcanic islands which is what I require.

      If I were to generate larger maps, particularly for a project in 3d, I would choose a faster algorithm.

      Good luck with your project 😉

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s