Random Map Generation

My name is Maria Garrigolas Ledo, student of the Bachelor’s Degree in Video Games Design and Development at UPC CITM.

This content is generated for the second year’s subject Project II, under supervision of lecturer Ramon Santamaria.

About the research: What are Random Generated Maps?

The procedural generation is the process to generate content algorithmically rather than manual.

In other words, random generated maps are created by computers instead of persons.

Height Formula Height Formula
Random generated terrain Random generated dungeon

Why do we want random generated maps?

Nowadays, a video game demands several materials to compose complex and large scene, carrying high costs in their content development. Developers use these algorithms to reduce the amount of time taken to create a game or certain features of it.

Also, from the player perspective, it is more enjoyable to play a diferent map every time. So replayability is also a very important factor.

Characteristics of a generated random map

Why is it good?

Why is it bad?

When should we use a random generated map?

Height Formula Height Formula
Minecraft No man’s sky

How can we create this algorithm?

The tricky part in procedural generation is not to make things random, but to make them in a consistent way despite it’s randomness. There are two types of maps:

Height Formula Height Formula
Outdoor map Indoor map

We will use different procedures to achieve each of them.

Dungeon Generation using Binary Space Trees

When making a dungeon you have to face the problem of filling the space with elements in a natural way.

First step we have to do is to divide a plane into two sets recursively. We divide until we can’t divide anymore or until we reach a maximum number of spaces.

Height Formula
Dividing a square into two recursively

Next step is to add borders: we got a random division, but we don’t want the rooms to use the whole space, so let’s add a method to cut their borders recursively. We can achieve that giving a regular or non regular margin between space wall and room wall.

Height Formula
Making rooms and connecting them using a binary space partition

The last step is to add corridors, we are going to do this by recursively connecting each node with it’s sibling.

Height Formula
Creating corridors

This should be the final result:

Height Formula
Final result

Perlin Noise

A common way to generate 2D maps is to use a noise function, such as perlin noise. This is what the noise function looks like:

Height Formula
Perlin Noise

To create a random terrain we need to store a seed, a math formula and set a frequency.

We assign each location on the map a number from 0.0 to 1.0. In this image, 0.0 is black and 1.0 is white.

Height Formula

Once you have this values, you interpretate numbers to spawn terrains.

TODOs

TODO 1: Create a FastNoiseLite object.

FastNoiseLite noise;

TODO 1.2: Set its Noise type to Perlin noise.

noise.SetNoiseType(FastNoiseLite::NoiseType_Perlin); 

TODO 1.3: Set the seed with SetSeed function.

noise.SetSeed(seed);

TODO 1.4: Set the frequency to 0.05.

noise.SetFrequency(0.05);

Output: Nothing will be shown on screen yet.

TODO 2: Store the values generated by Perlin Noise in app->map->height_map.

app->map->height_map[x][y] = noise.GetNoise((float)x, (float)y);

TODO 2.1: Noise must be always between 1 and 0 (use the following formula: (Noise + 1) *0.5).

app->map->height_map[x][y] = (noise.GetNoise((float)x, (float)y) +1) * 0.5;

Output

Height Formula Height Formula
TODO 2 TODO 2.1

TODO 3: Draw the different textures into the map.

if (value > 0 && value < 0.2) app->render->DrawTexture(app->scene->forestTex,pos.x, pos.y, NULL, scale);
else if (value > 0.2 && value < 0.4) app->render->DrawTexture(app->scene->grassTex, pos.x, pos.y, NULL, scale);
else if (value > 0.4 && value < 0.6)  app->render->DrawTexture(app->scene->sandTex, pos.x, pos.y, NULL, scale);
else if (value > 0.6 && value < 1)  app->render->DrawTexture(app->scene->waterTex, pos.x, pos.y, NULL, scale);

Output: The terrain will be shown in screen with its textures. Use [SPACE] to generate new terrains with the generated perlin noises!

Height Formula
TODO 3

Bibliography

Library used: Fast Portable Noise Library created by Jordan Peck

A video about 2D Terrain Generation using Perlin Noise published by Barney

Procedural generation applied to a video game level design written by Albert Carrión Díaz

Addition information to understand procedural dungeon