Skip to content
raneechu edited this page Aug 31, 2021 · 5 revisions

Purpose

The in-game pause menu allows the player to pause the game and resume it at a later time, while also providing other options such as restarting the level or returning to main menu.

Implementation

Key Components

  • PauseGameDisplay Creates the visualisation of the pause menu
  • PauseWinAction Handles the actions taken when the pause button is pressed
  • PopupMenuActions Handles actions after pressing buttons that are common across all pop up menus
  • PauseMenuPopup Triggers the pop up menus based on the status of the game
  • GdxGame Used to set and keep track of the game state

The game has been divided into three different states, with setter and getter methods being added into the GdxGame class allowing any classes that have the game passed as a constructor to access and alter the game's state.

 public enum GameState {
   RUNNING, PAUSED, OVER
 }

 public void setState(GameState gameState) {
   this.gameState = gameState;
 }

 public GameState getState() {
   return this.gameState;
 } 

The game is paused by checking the current game state. The update() functions in the render function of MainGameScreen will only be called if the state is GdxGame.GameState.RUNNING:

if (game.getState() == GdxGame.GameState.RUNNING) {
  physicsEngine.update();
  ServiceLocator.getEntityService().update();
}

Furthermore, if an action triggers the game to pause or resume, the game state is updated:

public void onPause() {
    logger.info("pausing game");
    if (game.getState() == GdxGame.GameState.RUNNING) {
        game.setState(GdxGame.GameState.PAUSED);
    }
}

public void onResume() {
    logger.info("resuming game");
    if (game.getState() == GdxGame.GameState.PAUSED) {
        game.setState(GdxGame.GameState.RUNNING);
    }
}

Usage

Add the pause menu functionality to the game by adding it to the createUI method in MainGameScreen:

Entity ui = new Entity();
ui.addComponent(new ...) // Other entities for the UI
.addComponent(new PauseGamePopUp(this.game, new PopupUIHandler(pauseMenuTextures)))

Menu Design

Table of Contents

Home

Introduction

Main Menu

Main Game Screen

Gameplay

Player Movement

Character Animations

Enemy Monster Design and Animations

Game basic functionalities

User Testing

GitHub Wiki Tutorial

Game Engine

Getting Started

Documentation

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally