Skip to content

Companion Alert Documentation

saakshigupta2002 edited this page Oct 5, 2023 · 4 revisions

Overview

CompanionStatsDisplay is a Java class that represents a user interface component designed to display a message alert for companion entity. This component is typically used in games that feature companions or allies, and it provides visual feedback to players regarding their health status. We can leverage the CompanionStatsDisplay class to craft a basic UI element that portray an alert when player's health is less than a specified value and can be used to alert various other vital statistics. Through the act of instantiating an instance of this class and integrating it into the game's user interface framework, players can be seamlessly immersed in a real-time alerts of information concerning their's health.

game_area

Propertie

table:

A layout container that arranges UI elements.

healthText:

A text representation of the companion's health status.

SCALE_REDUCTION:

A constant factor for scaling UI elements.

MESSAGE_DISPLAY_TIME:

The duration for which the message is displayed.

Constructor

CompanionStatsDisplay(boolean center, float offsetY, int health): Initializes a new instance of the CompanionStatsDisplay class. The constructor accepts parameters for positioning the UI, providing an offset, and abstracting the health element from CompanionFactory.

Screenshot 2023-08-31 at 11 53 14 AM Screenshot 2023-08-31 at 11 56 05 AM

Methods

create():

Initializes and adds UI actors to the stage. This method sets up the graphical components for displaying the companion's statistics.

addActors():

Adds UI elements such as the table and health message label to the stage. It arranges these elements using the LibGDX Table layout.

updateUIPosition():

Updates the position of the UI elements based on the companion's position and configuration settings.

update(float deltaTime):

Updates the message display timer and clears the message when the timer expires.

dispose():

Cleans up and removes UI elements when they are no longer needed.

Dependencies

LibGDX: The core framework for developing cross-platform games.

Future improvements

We have recognised that after sprint 1, there is commonality between the player alerts and the companion alerts. It would stick to best practice to combine these together and provide an abstraction for the alert class. In sprint 2, we will implement this, and provide a more consistent codebase, and upholding good software design patterns.

Sprint 2

In sprint 2, we are updating the alerts to actively track the companions location, so that all alerts look good and come from the companion. We do this by constantly sampling the companions location, and having a fixed offset to put the alert near the companion.

Clone this wiki locally