Sub topic 3
Designing Lose Conditions
A lose condition is a rule that ends a game session in defeat. The player cannot continue from the current state without starting over, loading a save, or accepting a major penalty. This chapter covers how to choose lose conditions, how to define them so they can be measured, and the mistakes that make defeat feel arbitrary.
This chapter assumes you know the core gameplay loop of a game and can read short Python functions that use conditionals. It also assumes you know the difference between a win condition (the rule that ends play in success) and a fail state (a setback the player can recover from). Those were introduced in earlier chapters.
What a lose condition does
A lose condition does three jobs.
- It creates tension. If nothing can be lost, no choice carries weight.
- It defines the boundary of acceptable play. The things that can end your run tell the player what the game considers dangerous.
- It gives the game a way to finish when the player cannot win. Without it, a stalled or hopeless session never ends.
Not every game needs one. A sandbox builder or a pure toy may have no lose condition at all. If your game has a win condition and any kind of risk, though, you almost always need a matching lose condition. Otherwise the risk has no consequence.
Common types of lose conditions
Most lose conditions fall into a small number of families. The table lists the usual ones with an example and the main design risk of each.
| Type | Example | Main risk |
|---|---|---|
| Resource depletion | Health reaches zero | Death spirals (see below) |
| Time limit | Timer expires before the goal is reached | Feels punishing if the limit is not clear |
| Loss of an asset | The base or objective is destroyed | Player cannot protect what they cannot see |
| Failure of a mission goal | The escort target dies | One mistake outside the player's control ends the run |
| Opponent success | The rival reaches the finish first | Outcome can feel decided before the end |
| Stalemate or lockout | No legal moves remain | Player may not notice they are already beaten |
A single game often combines several. A strategy game might end in defeat when the capital falls, when the economy collapses, or when a turn limit passes.
Make the condition measurable
A good lose condition can be written as a test on game state that returns true or false. If you cannot write that test, the rule is still vague.
Compare these two statements:
- "The player loses if things go badly."
- "The player loses when health is zero or below."
Only the second can be implemented, tested, and explained to the player. Vague conditions also cause disagreements inside a team, because each person pictures a different threshold.
Here is the function from the previous chapter's outcome logic, shown again because its structure matters for lose conditions.
from enum import Enum, auto
class Outcome(Enum):
PLAYING = auto()
WON = auto()
LOST = auto()
def evaluate(health, relics, relics_needed):
# Check the lose condition first, so a simultaneous win and loss
# resolves as a loss. Reverse the order to favor the player.
if health <= 0:
return Outcome.LOST
if relics >= relics_needed:
return Outcome.WON
return Outcome.PLAYING
print(evaluate(health=0, relics=3, relics_needed=3))
print(evaluate(health=5, relics=3, relics_needed=3))
print(evaluate(health=5, relics=1, relics_needed=3))Note two details. The check uses <= rather than ==, because damage can overshoot zero, and an exact-match test would miss a player at -3 health. And the order of the checks decides what happens when both conditions are true in the same frame. That is a design decision, not a coding accident. The first call above returns LOST even though the player collected every relic.
Decide who wins ties
When a player grabs the last relic with the same hit that drops their health to zero, the game must pick one result. Three common policies exist.
- Loss first. Safe for the designer, but players often read it as unfair, since they "got there."
- Win first. Friendly, and common in games where the goal is the emotional climax.
- Sequence by event order. Whichever event the engine processed first decides. This is the most honest in a strict sense, but it can depend on update order that players cannot see.
Pick one on purpose, write it down, and test it. In many games a win-first policy for simultaneous events is the better experience. The code sample's loss-first order is a stated default, not a recommendation for every game.
Resource depletion and the death spiral
Health is the most common lose condition, and it carries a known hazard. A death spiral happens when losing makes you more likely to keep losing. A player who is low on health, low on ammo, and behind on resources has the least ability to recover, so the defeat is often decided long before the game says so.
You have several ways to soften a spiral without removing the lose condition.
- Give small recovery paths, such as healing pickups that appear more often when health is low.
- Add catch-up mechanics so that being behind grants some advantage.
- End the game sooner when recovery is not realistic, so the player does not play out a lost position.
The last option is often overlooked. If a position is truly lost, a long wait for the formal defeat only wastes the player's time. Many strategy games offer a resign button for this reason.
Lose conditions with lives
Lives turn a single lose condition into a counter. Each death is a fail state until the last life is spent, and then it becomes a lose state. The same event, the player's death, plays two different roles depending on how many lives remain.
from enum import Enum, auto
class Outcome(Enum):
PLAYING = auto()
WON = auto()
LOST = auto()
class Run:
def __init__(self, lives, checkpoint):
self.lives = lives
self.checkpoint = checkpoint
self.position = checkpoint
def on_player_death(self):
# A death is a fail state while lives remain and a lose state when they run out.
self.lives -= 1
if self.lives == 0:
return Outcome.LOST
self.position = self.checkpoint
return Outcome.PLAYING
run = Run(lives=2, checkpoint=(10, 4))
run.position = (42, 7)
print(run.on_player_death(), run.position)
print(run.on_player_death(), run.position)The first death returns PLAYING and moves the player back to (10, 4). The second returns LOST. One edge case: the check self.lives == 0 assumes lives never starts below one. If a designer passes lives=0, the first death makes lives negative and the game never ends. Using <= 0 is the safer test, for the same reason as the health check above.
Where lose conditions go wrong
Most bad lose conditions fail in one of a few ways.
The player cannot see the cause
If the player is defeated and cannot tell why, they cannot learn. Instant deaths from off-screen sources, unexplained timers, and hidden thresholds all have this problem. Every lose condition should be something the player can observe before it triggers. A health bar, a countdown, or a "base under attack" warning all serve this role.
The player cannot predict the threshold
Players need a sense of how close they are. A hidden "reputation" value that ends the game at some unknown level gives no warning. Show the value or add intermediate warnings, such as a screen that reddens as health falls.
One mistake ends everything
A lose condition that triggers from a single small error feels harsh when the error is easy to make and the cost is large. This can be correct in some genres, such as roguelikes or hardcore modes, but only when the player has agreed to that deal. In most games, pair a sharp lose condition with a buffer, such as a health pool, so that one error costs part of the run rather than all of it.
The cause is outside the player's control
Defeats from random events, ally behavior, or lag feel unfair because no decision of the player's could have prevented them. Escort missions are a standard example. If the escort target dies because of its own poor pathing, the player is punished for a flaw in the AI. Either give the player tools to protect the target or do not make its survival a lose condition.
The lose condition conflicts with the goal
Sometimes a lose condition pushes players to avoid the interesting parts of the game. A strict time limit in an exploration game discourages exploring. Ask whether the lose condition rewards the behavior you want to see.
A flow of outcomes
The diagram shows how a single death event is handled in a lives-based game, ending in either a recoverable fail state or a lose state.
Testing a lose condition
Lose conditions are easy to test in code, and you should do it. Check these cases:
- The exact threshold, such as health of exactly zero.
- Overshoot, such as health of -10 after a large hit.
- Simultaneous win and lose events.
- The first frame of the game, to confirm that a new session does not start in a lost state.
- Resuming from a save made just before defeat.
The last case catches a subtle bug. If a game saves while the player is already dead or while a timer has already expired, loading that save can trigger an instant loss on load.
Beyond unit tests, watch real players. Look for moments where they are surprised by defeat. Surprise is a signal that the condition was not readable, even when the code is correct.
Choosing your lose conditions
Use these questions when you design a new one.
- What behavior should the condition discourage?
- Can the player see it coming, and can they act on what they see?
- Is the cost proportionate to the mistake?
- Does the game end sooner when the position is hopeless?
- What happens when win and lose happen at once?
If you can answer all five in one sentence each, the condition is probably ready for playtesting.
Exercise
A player has 1 life left and 2 health. A trap deals 5 damage at the same moment the player touches the final relic. Using the evaluate function from this chapter, what outcome results, and how would you change the code so that the player wins instead?
Show answer
The function checks health <= 0 first. Health becomes -3, so it returns Outcome.LOST even though the relic count reached the target. To favor the player, move the relics >= relics_needed check above the health check so a win is returned before the loss test runs. Whether to do so is a design choice about tie-breaking, and it should be documented and playtested.
Exercise
Why is if self.lives == 0 a weaker test than if self.lives <= 0 in Run.on_player_death, and what is one way a hidden threshold lose condition can still be made readable to the player?
Show answer
With == 0, a run created with zero or negative lives would skip past zero on the first death and never return LOST, so the game would continue in an invalid state. <= 0 covers that case. A hidden threshold can be made readable by showing the value on screen or by adding intermediate warnings, such as a color change or sound cue, before the threshold is reached.