I spent a lot of time on pathfinding this week. That wasn’t the plan, but as I was testing combat and thinking of ways to make it more interesting, I ran into a problem. When the player detects a trap, all enemies are made aware of the trap too because every entity is sharing the same pathfinding map. This prevents the player from luring an enemy into a detected trap. The initial solution I came up with was two pathfinding maps – one for the player and another for all enemies. Then I recalled the hack I implemented for the giant spider boss. The giant spider, unlike the player, is able to move across webs. The hack was to 1) swap out the main pathfinding map with a copy that treated the cells with webs as walkable 2) move the giant spider 3) restore the main pathfinding map. So, another pathfinding map was needed for enemies that can walk on webs. Then I thought about future enemies that I wanted to add, such as a ghost that can move through walls, and a bat that can fly over ground obstacles. Those would require their own pathfinding maps. I ended up building a new class to maintain multiple pathfinding maps, and added a pathfinding map attribute to each entity. Now, entities share pathfinding maps based on common movement constraints. And, if I need to add pathfinding maps for specific entities, that’s now possible.
I added player health regeneration because I wasn’t happy with items as the sole way to restore health. I’m not sure if I’ll keep this feature, but I’m trying it out as I balance combat. I don’t quite understand why, but playing with regeneration enabled feels better. Maybe it’s just because I’m not dying as often…
I reduced the size of a class from 900 to 300 lines using the Command design pattern. The class contained a dozenish actions. I pulled those actions into separate classes and the original class is now much easier to maintain. Large class size is one of the best clues that refactoring is needed.
Next week I’ll keep working on making combat more interesting. Also, I need to get the [2021 in RoguelikeDev] post out before January’s over.