Skip to content

Lives System

K0zzas17 edited this page Sep 25, 2021 · 6 revisions

Purpose

Like most action-Adventure games, this game will incorporate a life system, giving the player a set amount of tries to overcome certain obstacles before being forced to restart. Giving the player extra lives is a great incentive as death doesn’t mean the end of a game, but they only get to die a certain amount of times before having to restart. Player's will need to be considerate of how they proceed, as the further into a level they go, the more valuable these lives become. There could even be cases where the player might need to play through a section several times to overcome it, and the lives help improve the effect of these difficulties in tandem with the checkpoint system by giving a player a set amount of replays from a certain position in the level.

Design

Different icons were created in order to represent the lives. Since oxygen tanks are going to be used as a buff, the most likely choices will either be the astronaut head silhouette or the heart within the gear

Functionality

The lives system utilises the health and pop-up menus to determine it's outcome. The player will initially begin with 5 lives. When the player's health reaches 0, the PopUpMenuActions class will inform the system that the player has died. For this to be considered, a game state was added; RESPAWN, which is invoked when the player has pressed replay after dying.

This functionality begins when Initialisation of this class occurs when ForestGameArea.spawnPlayer() is activated, adding the Lives Component to the player entity components. The constructor for LivesComponent is included below:

public LivesComponent(int lives) {
     this.lives = lives;
}

The amount of lives is then displayed clearly on the UI for the player to see. The LivesComponent class activates again once the player has respawned after dying. In PopupMenuActions, on death the onReplayLoss() method is called, which sets the game to the RESPAWN state if the checkpoint hasn't been reached, and the CHECKPOINT if it has.

public void onReplayLoss() {
    if (area.getPlayer().getComponent(LivesComponent.class).getLives() < 1) {
        onHome();
    } else {
        if (area.getCheckPointStatus() == 1) {
            game.setScreen(GdxGame.ScreenType.CHECKPOINT);
        } else {
            game.setScreen(GdxGame.ScreenType.RESPAWN);
        }
    }
}

This changes the isDead variable in ForestGameArea to true; this thus decrements the global variable for lives by 1, and sets it to the player's LivesComponent component.

if (isDead()) {
    lives -= 1;
    newPlayer.getComponent(LivesComponent.class).setLives(lives);
} else {
    if(lives < 5 && !isDead()) {
        lives = 5;
        newPlayer.getComponent(LivesComponent.class).setLives(lives);
    }
}

public void setLives(int lives) {
    this.lives = lives;
    if (entity != null) {
        entity.getEvents().trigger("updateLives", lives);
    }
}

This process will continue whilst the number of lives is 0 or greater. When the player dies on 0 lives, they are sent back to the main menu and forced to start over from the beginning. A fresh set of lives will be given then.

UML Diagram

Below is a simple UML Diagram to display the lives component on the MainGameScreen

UML Diagram of LivesComponent

Interfaces

The lives will be displayed at all times during the game, and is represented by the silhouetted outlines of the astronaut's head. Player HUD

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