How I implemented invisible monsters in my roguelike

In just over 60 minutes I’ve implemented a new buff spell, a new monster ability and a new delayed effect that all combine to allow the caster to see invisible monsters for a predetermined period of time.

Read on to see how I did it.

My first and only real design choice (which turned out to be absolute key to the whole approach) was to use the monster status field to control when/if invisible monsters could be seen. This was implemented by generating a new flag known as CAN_SEE_INVISIBLE.

Once I had settled on this design decision and generated the flag in my code, I took a minute or two to think about the impact on my game and typed out those areas of my code that needed to consider invisible monsters the list looks like:

  • Update dungeon drawing routines for invisible monsters
  • Create test conditions to generate invisible monsters
  • Create a delayed effect to remove the spell buff

The first area I tackled though wasn’t on the above list it was implementing the spell buff itself. This was very easy to achieve as my code design is very modular and allows for code to be added incrementally. I then quickly and successfully tested that the spell could be cast and the buff would be applied to the player character.

Now that the buff was applied I needed some monsters to be marked as invisible so I could see them. The first step was to add some test code to the monster birth routines so that all monsters would be generated as invisible.

Once this was completed I updated the dungeon routines that specifically looked at drawing monsters, this update required a few extra lines of code to check if the status of the monster about to be drawn was marked as visible or invisible. If it was invisible then a further check is performed against the player status to see if they are buffed to see invisible monsters and if they are then the invisible monster is drawn.

To provide more confidence during the testing I implemented a feature into the code that allowed me to draw a star “*”, in the monster colour, where the invisible monster would be if the player character was not buffed to see invisible monsters.

After a little refining of my code I actually had the dungeon drawing routines correctly drawing or not invisible monsters.

The last thing for me to implement was a delayed effect to remove the buff after a period of time/turns. This was as easy as adding a “new” delayed effect to the processing queue and then a few lines of code to remove the buff once the delayed effect had expired.

I then play tested this fully functioning spell of see invisible monsters by using the Enchanter playable class – which comes with a See Invisible spell.

Before I started my final play testing I removed the “star drawing” test code. My testing consisted of applying the spell, letting it expire, watching the monsters vanish and then re-applying the spell and watching the monster reappear.

I was finally done with my coding and play testing and I had a new feature not only for the player but also for my monsters, overall I was happy with the results.

Looking to possible future design opportunities I can quite easily see (in my code) how I could implement other see buffs. For example if something was marked as HIDDEN then I could easily check for this status and either “find” it or not.

Over to you now, does my design make sense, could you see how you could incorporate the concept of invisibility into your game?

Use the comments section below to share your thoughts and comments.

This entry was posted in design, dungeon, graphics, magic, monsters, Spellcasting, spells and tagged , , , , , . Bookmark the permalink.