Randomly generating a 2d RPG world

Randomly generating a 2d RPG world

This is a compilation of all my posts about using procedural content generation to create a random 2d RPG world.

The first step is to create a heightmap. This randomly generated bitmap will serve as the basis of the world map. Then we can convert this heightmap to our world map. Finally we can generate some random names for our map (world name, city names, etc.)

Filtered Twice
Height map

Create the heightmap

Generating heightmaps using particle deposition

Using Gaussian blurring on heightmaps

A remote mountain cave.

Create the 2d world map

Creating a random 2d game world map

Creating a random 2d game world map, Part 2: Adding rivers and lakes

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

I had used an open source implementation of the A* algorithm to add roads between cities. Sadly, I have never written about it. But here is a link to the relevant code:

Adding roads to our world map

A city next to a river.

Generating random names

Algorithm to generate random names

A better algorithm to generate random names

A snowy island.

Finally here is a link to a Github repository where I had implemented these algorithms:

Gameproject Repo

TODO comments best practices

// TODO: filter employees by role

The best use for TODO comments is when you are actively working on a change set, adding TODOs that will be replaced with actual code as you work. These TODOs will be removed before you commit to source control.

In this case you add a TODO, signifying an intention to return later on to complete the code.

Before committing code to source control, it’s always a good practice to review all your changes with a diff tool. This is the perfect time to scan for leftover TODOs in the code and implement them.

Another case for TODOs is for something that will truly be implemented in a later commit. Before leaving those kinds of TODOs in the code ask yourself if you shouldn’t rather create an issue in your issue tracker. Otherwise this second kind of TODOs tend to accumulate and pollute the source code. They experience the same kind of code rot as old commented out code does.

TODOs that you leave after a commit should be for changes that are small, implementable in the foreseeable future and relating to source code rather than business processes.

Before leaving those kinds of TODOs in the code ask yourself if you shouldn’t rather create an issue in your issue tracker.

On larger projects you tend to see TODO comments which are several years old. Just today I found one that source control indicated was 3 years old. The person responsible for the comment may not even be working here anymore. While reading this specific comment could give me a general idea of what should be accomplished it does not do so clearly enough that I can go do it. Or why for that matters it needs to be done. You tend to see these often enough.

This is similar to commented out code, where nobody knows why the code was commented out in the first place and thus leave it as it is thinking it may be important. As time goes by there is less and less chance of someone actually knowing why the code was commented out. So it stays there until someone is brave enough to just delete the useless comment (how can it be useful if no one knows why it’s commented out). Keeping track of old code is the source control’s job anyway.

The Genesis project

I have decided to start a new project, it’s purpose is two-fold:

  1. do something I am really interested in (random world generation)
  2. be an excuse to use some tech that I want to use and to learn some new ones I am interested in learning

For this project I will specifically make it a point to use :

  • F#
  • Bootstrap
  • Angular2
  • VS Code
  • .Net Core and ASP.Net Core
  • ASP.Net Web API
  • TypeScript

I will also try to do as much of the development as possible on Linux (Mint 17.3 XFCE edition with zsh and oh-my-zsh). Switching to Windows 10 and Visual Studio Community Edition when I need to.

If I see something that doesn’t work or that I don’t like along the way (say I want to replace VS Code with Atom or Angular with React), I won’t bat an eyelid and just make the switch.

The project itself will be a website that allows visitors to create and display a procedurally generated world. I am naming it after the Genesis device from Star Trek III.

I have already created the GitHub repo. My time is severely limited so I don’t know how much time I will be able to invest in this but I don’t mind going with a slow and sporadic approach since this is a personal interest project.