Repository navigation
Death Screen Implementation
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.
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.
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.
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);
}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.
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);
}
});The Death Screen functionality follows this sequence:
- The player takes damage during gameplay.
- The player's health reaches zero.
-
CombatStatsComponentidentifies that the player is dead. -
ForestGameArea.isPlayerDead()checks the player's death state. -
MainGameScreendetects that the player has died. - The Death Screen is displayed.
- Normal game-world updates are stopped.
- The player selects an available option.
- Try Again returns the player to the main game.
- Main Menu returns the player to the main menu.
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.
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.
The Death Screen functionality was tested by running the game and allowing the player's health to reach zero.
Steps:
- Start the game.
- Enter the main game.
- Allow the player to receive damage.
- Continue until the player's health reaches zero.
- Observe the game.
Expected Result:
The player's death is detected and the Death Screen is displayed.
Result:
Passed.
Steps:
- Start the game.
- Allow the player to die.
- Observe the game screen.
Expected Result:
A YOU DIED popup appears over the game screen.
Result:
Passed.
Steps:
- Start the game.
- Allow the player to die.
- Observe the game after the Death Screen appears.
Expected Result:
The normal game-world updates stop while the Death Screen is displayed.
Result:
Passed.
Steps:
- Start the game.
- Allow the player to die.
- Click Try Again.
Expected Result:
The game returns to the main game screen and allows the player to restart gameplay.
Result:
Passed.
Steps:
- Start the game.
- Allow the player to die.
- Click Main Menu.
Expected Result:
The game returns to the main menu.
Result:
Passed.
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
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.
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.
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.
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.