Skip to content

Khemitron Industries

Amateur Game Dev, Gaming, and TTRPGs

Menu
  • Home
  • Game Dev
  • About
Menu

You Win Some, You Lose Some

Posted on 2025-04-14

It’s all well and good having a combat where you can move around and hit the enemies to deal damage, but eventually you’re going to reduce all the enemies to zero hit points (HP). Or maybe the enemies get lucky and it’ll be all your adventurers who get reduced to zero HP. What happens then?

Well, at the start of this week, in my game, nothing happened. Everyone on zero hit points could continue to fight on, striding around and striking each other endlessly. While I’m sure this would be a funny bug to find once every so often, in the long term, I think everyone would get sick of it. So it’s time to introduce some code to take care of the enemies dying when they reach zero hit points, and to stop the player taking actions for adventurers on zero HP.

Let’s delete some enemies

In keeping with both the Pathfinder 2E (PF2E) rules and XCOM gameplay, player characters and enemies have different behaviour when they reach zero HP:

  • Player characters fall unconscious and start dying
  • Enemies die outright and are removed from combat

I see no reason to deviate here – enemies being removed from combat on zero HP helps to keep things simple, both from a coding and game design point of view. The player characters being unconscious but dying, on the other hand, gives the player a chance to save their beloved adventurers.

In PF2E, a player character healed up from zero HP regains consciousness and can rejoin the fight, but is more likely to die if they’re reduced to zero HP again. I would like to keep this part of the rules in my game as it allows for heroic comebacks, but discourages the player from constantly reviving an adventurer and having them charge straight in with barely any HP.

Back to deleting enemies.

First thing on the agenda was preventing an enemy from taking further actions if they are reduced to zero HP. I added a check to my enemy AI that causes them to end their turn immediately if they’re on zero HP. This check probably won’t matter for a while since the only way an enemy can potentially take actions on zero HP is if they’re reduced to zero HP on their turn, which can’t happen at the moment but there are planned features that could have that effect.

Next I set about deleting the enemy from the game and ended up with this.

Defeating an enemy by dropping them to zero HP removes them from the Initiative Tracker and deletes their token from the map

This deletion and small animation was surprisingly difficult to achieve. When an enemy was deleted from the list of combatants, my original code removed the entire initiative tracker and rebuilt it from scratch. In theory, this wasn’t a major problem – it did it within a single frame, so nobody would ever have seen it. Unfortunately, however, whenever damage was dealt and the code tried to update the health bar, it was trying to update the old one. Which had been deleted. And that caused the game to crash.

So I rewrote the initiative tracker code so that only the deleted enemy was removed, which fixed that problem. However, there was a problem with the small white arrow that used to sit under the active combatant’s summary. This had actually been causing me several problems, so I just removed it entirely. If you go back to some of my previous posts and check, the arrow is there, but you’ll not see it in any of the gifs in this post.

They’re all gone… what now?

Once you’ve reduced all the enemies to zero HP, you win!

When every enemy is on zero HP, the animations finish and then you get a victory screen.

It’s nothing particularly special yet, and the continue button doesn’t do anything so you have to literally close and reopen the game to do anything else. It does, however, indicate to the player that they’ve won and I intend to spruce it up, along with the rest of the UI.

What about… losing?

As I mentioned earlier, when a player character drops to zero HP, they don’t die outright. In fact, you may have noticed in the previous animation that there’s a player character on zero HP who hasn’t been removed from the initiative tracker, or the battle map. Eventually, I will build a proper death and dying system, but for now I just disable the action bar for any player character on zero HP.

I had to modify the enemy AI a bit here so it doesn’t just stand next to a player character on zero HP and continue to beat them up while ignoring everyone else.

Prior to this change, the enemies would just stand beside characters on zero HP.

And if you let all your characters drop to zero HP…

All your characters dropping to zero HP means you lose (this combat)

Once again, I need to prettify the pop up more and make the continue button actually do something.

Dynamic actions

Something that’s not obvious in the above gifs is that the actions are now added to the action bar dynamically. This means I can have a list of actions for each character and create their own personalised action bar. Since there are only the two basic actions – Stride and Strike – at the moment, this doesn’t really mean much. In the future, however, this will become incredibly useful. Not to mention that it’s a necessary change – if it wasn’t dynamic, you might have the wizard’s spells appearing on the fighter’s action bar instead of the fighter’s charge or shielf block abilities, and nobody wants that!

A full gameplay loop?

We’re nearly there now. The work done this week to create simple win and lose conditions means that by this time next week I should be able to start a game on the world map, get a quest to spawn, send an adventuring party out, start the combat, win or lose, and then return to the world map to start everything again. That’s going to be very exciting to see!

Share on Social Media
facebook tumblr reddit emailwhatsapp

Like this:

Like Loading...

Recent Posts

  • Refactoring the World Map 2025-06-09
  • Using Themes to Enhance my Game 2025-05-19
  • Quality of Life Improvements – Nested Tooltips 2025-05-12
  • Improving Quality of Life 2025-05-05
  • Godot4.4 – Powerful Localisation with gettext 2025-04-27
©2025 Khemitron Industries | Design: Newspaperly WordPress Theme
%d