Game Over Screen - UQdeco2800/2021-studio-6 GitHub Wiki

Summary

The game over screen displays when the player has died. The game over screen contains several buttons that gives the user navigational options.

The current buttons on the game over menu are: Restart game button - Restart the game from the start of the prologue by setting the screen type to "MAIN_GAME". Return to menu button - Returns to the main title screen by setting the screen type to "MAIN_MENU". Exit button - Quits the game by calling game.exit().

Justification

Game Over

Purpose of a Game Over screen is to notify the player that the game has ended. No shit I died

Since the invention of electric pinball machines, "game over" has been a sign to the player that their game... is over. Either from death of their character, time limit, or end of a game, the game over screen is in almost all games which includes any amount of combat or survival elements.

It serves a similar purpose to a pause screen, where the game stops, and the player is given a choice to exit the game(to menu or exit the game entirely) or sometimes continue from your last checkpoint or death, or to restart/start a new run.

FTL Game Over

There are games which uses the screen frequently by designing the core gameplay to be challenging to an average player with no difficulty options. The player is often mocked by the screen, and it is as if the developers expected you to lose to their game and taste defeat. Some games go as far as to leave mocking messages to the player, taunting the player to try again to beat the game.

Risk of Rain 1

Some games show progress or achievements the player acquired throughout the run to show the player progress they've made or how great of a game they just had, encouraging them to do even better than before. Showing your score compared to other player's score can also add some competitive drive (but these are mostly for hardcore record setters as casual audience don't have time or skills to achieve the best score).

Minecraft's game over screen

What we want to achieve with our game

Fireflies doesn't have a clear identity as to what kind of game it wants to be yet. (If game over is just a mention to the player of their failure or end of the player's attempt at finishing the game and therefore they have to restart.) Game lacks a score system. Once these things are established, it'll be clearer what features of a game over screen might be beneficial for the game's enjoyability.

Conclusion, for now(as of week 1 of sprint 2), an empty screen with game over and options for players to navigate to the menu or to restart the game is sufficient.

Class Overview

  • GameOverScreen.java handles:

    • Load/unload of all the assets required for the game over menu.
    • Creating the UI component of the main game.
  • GameOverDisplay.java handles:

    • Adding the assets on the stage and determining the layout of these assets. The layout is controlled through the use of a table.
    • Adding the background image (currently is the words "Game Over").
    • Resize elements when a screen resize has been detected.
  • GameOverActions.java handles:

    • Functionality for when a button is activated within the game over menu by listening for the button events.
  • MenuUtility.java handles:

    • Common functionality between menu screens such as:
      • Adding listener events to the buttons.
      • Adding button sound effects.
      • Changing button styles within a table

Unified Modeling Language

Note: Right click and select open image in new tab to see the full quality image.

This is the UML diagram that shows the connection between game over related classes. For simplicity, only the classes immediately connected to the game over classes are shown on this diagram.

Note that the GameOverAction class receives the button events through the EventHandler sending an event to the entity attached to the UIComponent class (through the parent Component class). This has been intentionally left out to keep the focus on the game over classes.

Assets loaded for the game over screen:

  • images/gameover.png: This is the temporary background of the game over menu that currently contains the words "Game Over" on a black background. The game over menu will be designed in a later sprint once some of the other UI components have been designed (for design consistency).

  • sounds/rollover.mp3: This is the sound effect that is played whenever the user rolls over a button, i.e. when the "enter" listener for a button is activated. The sound effect can not be played again until the "exit" listener has been activated.

  • sounds/click.mp3: This is the sound effect that is played whenever the user activates a button. Note that this sound effect is not disposed of immediately with the rest of the screen and is instead disposed of after a 0.2 second timer to allow the sound effect to finish.

How to add a button

Within the GameOverDisplay class "addActors" method:

  • Step 1 - Add a new TextButton
TextButton restartBtn = new TextButton("Restart Game", skin, MENU_BUTTON_STYLE);
  • Step 2 - Call the MenuUtility.addButtonSelectListener method with the following parameters: Entity entity, Button button, and String eventTrigger. When a user activates the new button, this will play the click sound effect and run the event trigger specified.
MenuUtility.addButtonSelectListener(entity, restartBtn, "restart");
  • Step 3 - Call the MenuUtility.addButtonRolloverListener method with the button as it's sole parameter. This will add the rollover sound when the user mouses over the new button.
MenuUtility.addButtonRolloverListener(restartBtn);
  • Step 4 - Add the button to the table called "table" and add the cell padding.
table.add(restartBtn).pad(CELL_PADDING_LARGE);

Within the GameOverActions class:

  • Step 5: Within the "create" method, add a new listener for the event trigger you have specified in step 2.
entity.getEvents().addListener("restart", this::onRestart);
  • Step 6: Add a new method that the new event trigger (from step 5) will call when the button is selected.
private void onRestart() {
    logger.info("Start game");
}

How to initiate the game over menu

Call the setScreen method to display the GAME_OVER screen:

setScreen(ScreenType.GAME_OVER) 

Further Reading