Simple Map Drawing
v3 Tutorials
Goal
In this tutorial we’ll begin using the Map features of RogueSharp. We will create our own DungeonMap class that will start off very simple but give us lots of room for growth. We’ll also be drawing this to the map sub console and displaying it on the screen.
Creating the DungeonMap
When it comes to the Map class in RogueSharp it is designed to be generic so that it can be used in a variety of games. It has plenty of functionality for path-finding, determining field-of-view, selecting Cells and more.
What RogueSharp doesn’t have is any concept of doors, stairs, traps, bookcases, torches, or any other dungeon features that are specific to an individual game’s domain. These are really up to the game designer and not something that I feel should be baked into an engine.
With that said, we do really want all of these features in our game, so how can we add them and still use RogueSharp? The answer is we can create our own class that inherits all of the features of RougeSharp’s Map class but at the same time extends it with the features that are specific to our game.
Start by creating a new class in the Core folder called DungeonMap.cs and add the following code to it.
You’ll notice on line 7 that our DungeonMap class inherits from the base RogueSharp Map class. This means that we already get access to everything that Map can do!
The drawing code is pretty simple. We iterate through every Cell in the Map and then choose how to display it based on if it is explored, if it is walkable, and if it is in field-of-view or not.
At this point we don’t have any special map features that actually require us to have our own class. Don’t worry though, those features are only a few tutorials away.
Creating the MapGenerator
Now we need a class that will be responsible for generating interesting maps for us. Make a new folder called Systems and inside the folder create a new class called MapGenerator.cs
To start off with we’ll make one of the simplest maps. It will be all open floors with a wall around the entire edge of the map.
Add the following code to MapGenerator.cs
As with the DungeonMap, the MapGenerator also is not that interesting at this point but it gives us a solid foundation for adding features in the future.
Your project file structure should now look something like this:
Hooking up the MapGenerator and Drawing
To start using our DungeonMap we need to first add it to Game.cs
Then in our Main() method of Game.cs we need to use our MapGenerator to create our DungeonMap.
Now that the map is created all that is left is to draw it in our OnRootConsoleRender() method of Game.cs
If everything worked when you run the game you should now see the map console has been replaced with this:
If it didn’t work, don’t worry. The complete code so far can be found here:
https://bitbucket.org/FaronBracy/roguesharpv3tutorial/commits/tag/03BasicMap
Also, feel free to leave me comments if you have questions. I’ll do my best to answer them quickly.