Skip to content

Player State Manager

SirAardvark edited this page Sep 20, 2021 · 9 revisions

Purpose

As the game grows in complexity, the player can be in a variety of different states. As such, the current method of determining the players state will eventually become too difficult to use, and therefore a new PlayerStateComponent class will be made to handle this.

Usage

This class will be important for animations. The method getStateAnimation returns a string based on the Player's Health and Movement state. As such, as long as these strings matches the names of the images for animation, this method can be called whenever the player's state changes such that the players animation changes aswell.

UML

UML Diagram

Implementation

Java enums were used to store constant variables to describe the player's Health, State and Direction:

enum Health {
    NORMAL, // 100 - 90 Health
    ROUGH, // 90 - 50 Health
    DAMAGED, // 50 - 10 Health
    DEAD // 0 Health
}

enum State {
    STATIONARY,
    WALK,
    SPRINT,
    JUMP,
    SPRINT_JUMP
}

enum Direction {
    LEFT,
    RIGHT
}

General getter and setter methods were implemented, as well as getStateAnimation() which uses switch statements to determine what animation the player should be in.

Additionally, the manage() method was implemented in order to determine which state the player should be in if multiple states are true. For example, if the player is moving left, sprinting and jumping, they should be in the SPRINT_JUMP state with LEFT direction

Methods to update and manage states are called within the KeyboardPlayerInputComponent class, as this class handles key up and key down events.

Testing & Validation

The PlayerStateComponentTest uses JUnit5 to test all the methods of the class.

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