Monster Stats
v3 Tutorials
Goal
During this tutorial we’ll show the monster health bars in the right hand stats panel, but only when they are in line-of-sight to the player.
Adding a DrawStats() Method to Monster
As you can see in the image above, the goal for drawing monster stats is to first display the symbol of the monster in the appropriate color followed by the monster’s name. Behind the name is a health bar that will decrease based on the percentage of monster health remaining.
Open Monster.cs and add the DrawStats() method as follows:
I tried to add comments to the code to help make it easier to follow along.
Updating the DungeonMap Draw() Method
Next we need to do a bit of work to DungeonMap.Draw(). It needs an extra parameter statConsole so that when we are drawing monsters, we can also draw out their stats. It is also important that we keep a count of the number of monsters that we have drawn so far. Each time we draw a new health bar stat block for a monster we want it to be below the previous one we drew so that’s why we pass this index into monster.DrawStats().
Cleaning up Clear() Methods
If you remember from our previous code for our Draw() methods on DungeonMap and MessageLog we call the Clear() method on the corresponding RLConsole every time anything changes. So what this means is that if a player or monster changes position, we Clear() the whole map and redraw everything. Although this may not be the most efficient way to do things, it does make the code a lot more simple and it should be good enough for our purposes.
The problem is that currently the Clear() calls are spread out in several places. Remove the console.Clear() calls in DungeonMap.cs and MessageLog.cs
Then open Game.cs and modify the OnRootConsoleRender() method.
If you run the game now you should see the monster health bars as you find them around the map. We still can’t interact with the monsters but we will be able to soon.
As always the code for the tutorial series so far can be found on Bitbucket:
https://bitbucket.org/FaronBracy/roguesharpv3tutorial/commits/tag/11MonsterStats
Bored waiting for the next tutorial post? The completed project is already available on Bitbucket.