top of page

Procedural Generation

This project demonstrates the implementation of a simple procedural level generation algorithm. When coming up with ideas for this project, I was reminded that I had always wanted to learn about procedural level generation in video games. After doing research and studying various methods of implementation, I found a way to do it that seemed simple enough to complete with my limited time frame and availability.

How I Did It

I went into this project with a fairly simple plan. I wanted to learn how to do simple procedural level generation. While I had visions in my head of using complex algorithms to place every individual tile within a level according to some set rules, I found that I had dreamed a bit too big. In my studies, I found that fully delving into more complex methods of procedural generation was far out of scope for me. I settled for something more simple, and got to work.

The method I chose to study is inspired by the hit game Spelunky. This algorithm takes a series of room templates and picks random ones to spawn in a grid in order to make a whole level. Each room is made up of multiple different spawn points, represented by empty game objects. Each spawn point will spawn a tile at its location when the room is created. This would allow each tile to be treated as a unique object if you wanted to allow the player to interact with them individually. It also allows the shape of each room to be freely changed and edited easily. Pictured below are two different room types, before and after the game has begun.

ClosedRoom.JPG
BasicRoom.JPG
ClosedRoomGenerated.JPG
BasicRoomGenerated.JPG

I made a few different types of these rooms to add some diversity to the level. In order to have more interesting and varied rooms, I then added more spawn points that could randomly spawn a tile within the room. As well as others that could randomly spawn premade chunks and shapes. The green points can spawn either a tile or nothing, while the blue points can spawn a tile, a premade chunk, or nothing.

GenDemo.JPG
TileDemo.JPG

Once I had enough of these premade room templates, making sure each would generate with different random terrain, it was time to start actually making the level itself.

ezgif.com-gif-maker (6).gif

As demonstrated above, the generation works fairly simply. The code chooses a place to start at the top of the level and creates the spawn room. It then chooses a random direction, moves there, and spawns another random room, which itself randomizes between the different templates for that room type, which creates a fully randomized layout. If the algorithm tries to move outside of the set boundaries, or back the direction it came from, it will simply pick a new direction, all the way until it reaches the bottom of the map and tries to go down again. At that point, it will stop the generation.

The reason I am generating the level like this and not just all at once randomly is to ensure the existence of what's called the "critical path". This "critical path" guarantees that there will always be a path for the player from the start to the end, and there won't be a wall blocking any progression. While doing this, I'm also making sure that the previous room generated actually has an opening that leads into the current room. Once the full path is created, every empty grid space in the level then just spawns a random room, completing the level generation.

Challenges

As mentioned before, I was looking to create something more complex than this, and delve deeper into the intricacies of procedural generation. However, that was far more complex than I had planned for, and I ended up just not having the time to go deeper. I had a hard time figuring out what I could do to make this project more interesting for me, but once the basic implementation was done, I realized that doing anything more was completely out of scope, so I worked on implementing the tile randomization within each room.

Were I to attempt this project again, I might try more methods of generation within simple examples, rather than attempting to flesh out each one. I feel like I spent too much time just on this one simple method, and didn't really learn a whole lot about the many other forms of procedural generation out there.

That being said, I'm glad I did this project, as I have learned techniques in making unique and procedural levels, and I can't wait to learn even more in the future.

bottom of page