Implementing a Random Dungeon Generator in Unity: The Tile and Layer Class

Today I want to talk about the implementation for the tile class and layer class I am using to generate rooms for my dungeon generator.

Let’s begin with the Tile class, which will be in charge of instantiating a single object (this being a sprite) into a given point in the game’s scene. I decided that in order to make this class more designer friendly the object to be generated would be an instance of a given prefab. In this way, the prefab will contain the necessary components depending on whether it will be part of the floor, walls or entities.

Implementation of Tile class : Go to github

After having my tile class implemented, the next step in the list was the Layer Class. The job of this class was to be used as a base class that I inherit to implement a class for other layers (floor,walls, etc). This class would contain the parameters that would be used to set the position of the layer, size, number of rows and columns and most importantly a list of the tiles that form the layer. At the same time, in order to keep tiles organized I decided that it would be useful to have an instance of the layer to be instantiated, and then parent all the tiles to this one. In that way it would be easy to know what layer each tile belongs to.

The Layer class also contains the methods that generate the layer, draws the layer on the world and sets a parent to the current layer, the latter one in order to set the layer under a specific room!

Implementation of Layer class: Go to github

These are the two major classes that are needed in order to create a layer for a room. And well, this could be used to create any type of sprite sheets, you could create children of the layer class that would implement anything you desire!!

This is it for now, On my next post I will share the implementation of the Floor, Wall and the beginning of the Room Class!

This is very exciting for me! 🙂

0 thoughts on “Implementing a Random Dungeon Generator in Unity: The Tile and Layer Class

Leave a Reply

Your email address will not be published. Required fields are marked *