Skip to content

Death Screen Implementation

rashim kaur edited this page Aug 29, 2026 · 1 revision

Overview

The Death Screen feature provides a clear visual response when the player dies. When the player's health reaches zero, the game detects the player's death, displays the Death Screen, and stops the main game world from continuing to update.

The feature also provides a Try Again option, allowing the player to restart the game after dying.

Changes Made

1. Player Death Detection

A method was added to ForestGameArea to determine whether the player is dead.

public boolean isPlayerDead() {
  CombatStatsComponent stats = player.getComponent(CombatStatsComponent.class);
  return stats != null && stats.isDead();
}

This method retrieves the player's CombatStatsComponent and checks whether the player is in a dead state.

The method returns true when the player is dead and false otherwise.

2. Death Detection in MainGameScreen

MainGameScreen checks whether the player has died during the game update.

When the player is detected as dead, the Death Screen is displayed and the normal game update is stopped.

The death-screen state is tracked using:

private boolean deathScreenShown = false;

The game checks the player's death state during rendering:

if (forestGameArea.isPlayerDead()) {
  deathScreenShown = true;
  deathScreenDisplay.showDeathScreen();
  return;
}

This prevents the normal gameplay rendering and updates from continuing after the player has died.

3. Death Screen UI

The DeathScreenDisplay class is responsible for creating and displaying the Death Screen user interface.

The popup contains:

  • A YOU DIED title.
  • A Try Again button.
  • A Main Menu button.

The popup is initially hidden:

rootTable.setVisible(false);

It is displayed when the player dies using:

public void showDeathScreen() {
  rootTable.setVisible(true);
}

4. Try Again Functionality

The Try Again button allows the player to restart the game after dying.

The button is connected to the game's main game screen:

retryButton.addListener(
    new ChangeListener() {
      @Override
      public void changed(ChangeEvent event, Actor actor) {
        game.setScreen(ScreenType.MAIN_GAME);
      }
    });

This allows the player to return to gameplay after selecting Try Again.

5. Main Menu Functionality

The Main Menu button allows the player to return to the main menu.

The button is connected to the main menu screen:

menuButton.addListener(
    new ChangeListener() {
      @Override
      public void changed(ChangeEvent event, Actor actor) {
        game.setScreen(ScreenType.MAIN_MENU);
      }
    });

Game Flow

The Death Screen functionality follows this sequence:

  1. The player takes damage during gameplay.
  2. The player's health reaches zero.
  3. CombatStatsComponent identifies that the player is dead.
  4. ForestGameArea.isPlayerDead() checks the player's death state.
  5. MainGameScreen detects that the player has died.
  6. The Death Screen is displayed.
  7. Normal game-world updates are stopped.
  8. The player selects an available option.
  9. Try Again returns the player to the main game.
  10. Main Menu returns the player to the main menu.

Death Screen Layout

The Death Screen is displayed as a popup over the game screen.

The interface contains:

        YOU DIED

      [ Try Again ]

      [ Main Menu ]

This provides clear feedback to the player and gives them an immediate choice after death.

Files Involved

The main files involved in the Death Screen implementation are:

  • ForestGameArea.java – provides the player death-state check.
  • MainGameScreen.java – detects player death and controls the Death Screen state.
  • DeathScreen.java – represents the Death Screen screen.
  • DeathScreenDisplay.java – creates and manages the Death Screen popup and buttons.
  • MainGameActions.java – provides game actions used by the main game.

Testing

The Death Screen functionality was tested by running the game and allowing the player's health to reach zero.

Test 1: Player Death Detection

Steps:

  1. Start the game.
  2. Enter the main game.
  3. Allow the player to receive damage.
  4. Continue until the player's health reaches zero.
  5. Observe the game.

Expected Result:

The player's death is detected and the Death Screen is displayed.

Result:

Passed.

Test 2: Death Screen Display

Steps:

  1. Start the game.
  2. Allow the player to die.
  3. Observe the game screen.

Expected Result:

A YOU DIED popup appears over the game screen.

Result:

Passed.

Test 3: Game Stops After Death

Steps:

  1. Start the game.
  2. Allow the player to die.
  3. Observe the game after the Death Screen appears.

Expected Result:

The normal game-world updates stop while the Death Screen is displayed.

Result:

Passed.

Test 4: Try Again

Steps:

  1. Start the game.
  2. Allow the player to die.
  3. Click Try Again.

Expected Result:

The game returns to the main game screen and allows the player to restart gameplay.

Result:

Passed.

Test 5: Main Menu

Steps:

  1. Start the game.
  2. Allow the player to die.
  3. Click Main Menu.

Expected Result:

The game returns to the main menu.

Result:

Passed.

Dependencies

No additional external dependencies were required for the Death Screen implementation.

The implementation uses existing game systems and components, including:

  • CombatStatsComponent
  • Existing entity and service systems
  • Existing screen management
  • Existing UI components
  • Existing game action mechanisms

Integration With Existing Systems

The Death Screen integrates with the existing player combat and health system.

The existing CombatStatsComponent is used to determine whether the player has died:

stats.isDead();

The Death Screen does not introduce a separate health or combat system. Instead, it responds to the existing player death state.

This allows the Death Screen to integrate with the existing game architecture without changing the underlying combat mechanics.

Design Considerations

The Death Screen was designed to provide a clear game-over state without requiring the player to close or restart the application.

A separate death-screen state is used to ensure that the Death Screen is not repeatedly triggered every frame after the player dies.

The game also stops the normal game-world update flow after death so that the player and other gameplay elements do not continue behaving as though the game is still active.

Limitations and Notes

The Death Screen relies on the existing player death system to determine when the player has died.

The implementation does not modify the underlying combat or health calculation.

Instead, it detects the existing dead state and provides the appropriate visual response and player options.

Summary

The Death Screen feature adds a dedicated game-over response when the player dies.

The implementation:

  • Detects the existing player death state.
  • Displays a YOU DIED popup.
  • Stops normal game-world updates after death.
  • Provides a Try Again option.
  • Provides a Main Menu option.
  • Integrates with the existing combat, entity, screen, and UI systems.
  • Does not require any new external dependencies.

Table of Contents

Home

Start here

Enemies and combat

Attacks and effects

Winning

Testing

Game systems

Player
Items, loot and shops
Maps
NPCs and UI

Game engine

Entities and components
Services and tools
Input
Rendering and world

Links

Javadoc

Clone this wiki locally