I’m currently working along with two friends on a Legend of Zelda clone using Unity 2D. Like in the original, dungeons will be a major part of the game, since is where the player will encounter most of the enemies and bosses.
I wanted to take dungeons to a higher level, and instead of me creating the dungeon from scratch, I thought of implementing a tool that would create the dungeons for me, while allowing me to set the size, objects and sprites. At first glance this could seem a bit tricky but in the end it would save a big chunk of my time that I can put towards another feature in the game. In the end, I believe that you will be able to see that when something is “random”, it doesn’t mean that you can also have control over it!
This is how I have broken down the implementation of the dungeon generator:
1. Create Tile Class – This class will be in charge of creating one tile on the screen. It will allocate the tile’s layer id depending to the layer that it belongs to!
2. Create a layer Class – This class will be in charge of allocating a set amount of tiles on the screen. The layer will also have an id, which will indicate its depth/order with respect to other layers.
3. Create child layer Classes – The idea is to have each ‘part’ of the room in separate layers. There will be a layer for the floor, then walls, objects, enemies, etc. The reason why I decided to do this is to give more freedom to the person who is using the tool!
4. Create layer’s layouts – The floor and walls of a room will not differ from one room to another. However, items, objects and enemies in a room might be ‘layed out’ differently. If you look at games like the binding of Isaac you might notice that the layout for rooms are used multiple times. YES! that’s the trick (or I least I think so), although your room might be randomly generated, it doesn’t mean that you won’t have a way to know how the room will look like. If you think about it, this way objects in the room will appear without disrupting the gameplay.
5. Create Room Class – After all the layer classes and its components are ready, then I will put these together in a room class. The room class will take control over how the layers are generated, and since I’m using a more data driving design, I will be able to set as many layers as I desire!!! with the exception of the walls and floors since there’ll be only one layer for both.
6. Implement Dungeon Class – This will be the trickiest one, since not only I will have to make sure that rooms are created in their corresponding locations, but rooms should also be allowed to ‘communicate’ between each other in order to set the correct destinations from one room to the next one! This class will contain rooms in a data structure, and each should be editable from Unity’s inspector!!!
I believe this is basically all the steps that I will take in order to complete the generator!!! I have made a major progress and it’s looking pretty good!! On my next post I will cover steps one and two!