-
Notifications
You must be signed in to change notification settings - Fork 9
Pause Game
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.
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:
-
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 fromMainGameActions
. -
MainGamePauseDisplay
class implements the functionality of the buttons in the window, by creating Listeners for each button and triggering different events, as found inMainGameActions
. -
MainGameActions
class created functions and listeners for these functions, as to be accessed byPauseWindow
andMainGamePauseDisplay
, as well as any other class looking to implement pause functionality. -
KeyboardPlayerInputComponent
class modified the functionkeyDown
to include the inputKeys.ESCAPE
, which will also trigger thePauseWindow
to open.
These functions from MainGameActions
include:
-
onPauseButton
: createsPauseWindow
display and pauses game. -
onExit
: exits the game to the main menu without openingPauseWindow
. -
onControlsButton
: switches screen toControlScreen
. -
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 fromKeyboardPlayerInputComponent
class.
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();
}
Here is the testing plan for the Pause Game functionality.
To enlarge: Right click -> Open image in new tab
Escape Earth Game
Interaction Controller and Interactable Components
Game and Entity Configuration Files
Loading Game Configuration Files