Skip to content
Sadra Bayat Tork edited this page Oct 4, 2021 · 1 revision

Implementation

The pause menu is implemented as an invisible UIComponent similar to the low health bloodied view which is set to visible using an event handler which in turn is called by an input component when the "p" button is pressed. Once p is pressed again the the same input handler toggles the visibility of the pause menu. The menu itself however, is only a small part of the feature. Once the game is paused all in game activity and movement must stop and once the game is unpaused again, the activity must resume. This was implemented by creating a pause attribute in the GameTime class which make swithes the time scale from 1 to 0 once set to true. This makes all the features that rely on game time such animations to pause which in turn causes both player and enemy movement to pause. However, features that don't rely on animations such as hit scan arrows or enemies looking at different direction still continues. Furthermore, while animation for projectile stops, sound cues and damage of the arrows continue implying that the arrow is still progressing in the background. To stop this AITaskComponent which controls the AI of the enemy was altered so different tasks queued which simulate the AI of the enemies and enemy projectiles were not processed while the game time was paused. This stopped all enemy and projectile movement, damage, etc.

Code

Below is the code snippet of the addition of pause related functions to game time. Since game time can be accessed globally all features in the game can have specific behavior for when the game is paused or utilize the pause themselves for example for displaying cutscenes

/**
 * @return whether the game is paused
 */
public boolean isPaused() {
    return paused;
} 

/**
 * Pauses the game
 */
public void pause() {
    timeScale = 0f;
    paused = true;
    previouslyPausedAt = this.getTime();
}

/**
 * Unpauses the game
 */
public void unpause() {
    timeScale = 1f;
    paused = false;
    timePaused += getTimeSince(previouslyPausedAt);
}

Table of Contents

Home

Design Document

Design Document

Design Document

Game Engine

Getting Started

Entities and Components

Item Drops from Entities

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Map Generation

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally