Procedurally Generated Dungeon

C#

Unity

In this project a level or dungeon is randomly generated through the use of ‘Perlin Noise’. It’s a small 2D-project made by Wayne in Unity Engine and programmed by him in ‘C#’. First it generates a texture based off of the engine’s own Perlin Noise generation. Wayne was able to give it its proper scaling for use as a level. The pixels are enlarged to simulate actual chambers that can be connected to eachother through smaller bridges.

Wayne was able to implement the randomization element through the use of a random number and adding it to every pixel on the texture. The Unity Engine’s ‘grid’ features makes it easier to place tiles. To convert the texture to a grid of tiles, you first have to convert the texture’s resolution to the size of the grid, taking into account the size of each tile.

The example below (PerlinNoiseTexture.cs) shows what to look for when placing a tile at a certain position. In this case, the amount of red is used as a determening factor for placing the tiles. This way, the Perlin Noise generates a level for you.

The example below also shows how bridges between chambers are created using the center of each chamber. The position of the ‘center points’ are put in a list and they determine the possibility of them having the same axis by index. That is why the ‘Selection Sorting’ algorithm is used.

Wayne has yet to implement a ‘randomize button’ so the generation of a level happens in-game, instead of starting the build over and over.