Skip to content

Pause Game

Rachit Chaurasia edited this page Oct 27, 2023 · 3 revisions

Overview

Pause Game is a functionality developed which allows the game to be 'paused' whilst a window or popup is showing. It does so by disabling every entity in the game, as well as applying full immunity to the player to inhibit them from taking damage. In conjunction with the pause functionality, the InputOverrideComponent is also used to restrict the inputs the player can do (eg. walk, attack etc), in order for the game to be genuinely 'paused'.

The Pause Button will replace the exit button which is located in the top right corner of the screen when in-game and will give players the option to either return to the current game, exit to the main menu or access a separate screen Controls, to learn about the controls and possible actions of the game. The pause button implements the pause game functionality.

Design

The final design chosen for the pause button was drawn to emulate a metal panel with screws, in order to match the aesthetics of the spaceship and therefore align with the Game Design objective. The text for the title and buttons was the chosen font of Kenvector Future Thin. The design can be seen below:

image

Key Components for Pause Functionality

  • PauseWindow class creates the UI element of the pause button, by creating buttons for 'Return to Game', 'Controls' and 'Exit to Main Menu', as well as the label of 'Game Paused'. It also associates the buttons with the different events from MainGameActions.
  • MainGamePauseDisplay class implements the functionality of the buttons in the window, by creating Listeners for each button and triggering different events, as found in MainGameActions.
  • MainGameActions class created functions and listeners for these functions, as to be accessed by PauseWindow and MainGamePauseDisplay, as well as any other class looking to implement pause functionality.
  • KeyboardPlayerInputComponent class modified the function keyDown to include the input Keys.ESCAPE, which will also trigger the PauseWindow to open.

These functions from MainGameActions include:

  • onPauseButton: creates PauseWindow display and pauses game.
  • onExit: exits the game to the main menu without opening PauseWindow.
  • onControlsButton: switches screen to ControlScreen.
  • onReturnButton: returns player to current game and resumes game functionality.
  • paused: disables all entities and sets player health to immune.
  • resumed: enables all entities and sets player health to non-immune.
  • isWindowOpen: checks if there is already a window open, initially from KeyboardPlayerInputComponent class.

Implementation of Pause Functionality

Classes that implemented pause functionality when creating and removing windows/display: ShipInteractionPopup, CompanionInventoryDisplay, UpgradeDisplay, DialogueBox, ExtractorMinigameWindow and LabWindow.

For pause functionality to be implemented into a window or popup, in order for the game to 'pause' when it is open and 'resume' when it is closed, the following code must be added (note placeholder names (<>) are used):

In the create() function:

    public static <DISPLAYTYPE> create<DISPLAY>() {
        ......
        ......
        ServiceLocator.getInputService().register(inputOverrideComponent);
        for (Entity mainGame : ServiceLocator.getEntityService().getEntitiesByComponent(MainGameActions.class)) {
            mainGame.getEvents().trigger("pauseGame");
        }
        ......
        ......
        return new <DISPLAY>();
    }

In the remove() function:

    public static boolean remove() {
        ......
        ......
        ServiceLocator.getInputService().unregister(inputOverrideComponent);
        for (Entity mainGame : ServiceLocator.getEntityService().getEntitiesByComponent(MainGameActions.class)) {
            mainGame.getEvents().trigger("pauseGame");
        }
        ......
        ......
        return super.remove();
    }

Testing plan

Here is the testing plan for the Pause Game functionality.

Class interaction / UML Diagrams

UML Pause Functionality

To enlarge: Right click -> Open image in new tab

Clone this wiki locally