Skip to content
Sadra Bayat Tork edited this page Sep 13, 2021 · 8 revisions

Overview

Player's death is marked by a fade into black and a death screen that is displayed afterwards. The functionality is implemented in the MainGameScreen.java render method where a function called isPlayerDead ran at every frame. The function checks if a player health is 0 and initiates the fade and changes the screen afterwards.

Code Structure

Two new classes were created and added as components of the player death screen to implement the death screen feature. First, is the DeathDisplay class which includes all the graphical elements of the display. The second, is the DeathActions class which handles the functionality of the death screen and includes the event handler functions. Both of these classes extend their MainMenuScreen equivalent classes.

deco (1)

Approach

Since we need a game instance to change screens, our options are greatly limited. As for event listener and handlers, each entity can only access event handlers of its components so player entity's components such as combat stat and health display can trigger a death screen in their "sibling" components which then in turn would require an instance of game to enact functionalities such as restarting or exiting. However, we can use service locator to access entities from anywhere which was another suggested solution. This is also somewhat limited. Currently EntityService contains a private array of all entities and an update function which updates each entity in this array and then in turn updates their components. This leads to the same problem as before where we need an instance of game since even if a component is updated, it still can only access its own or its siblings event handlers which also require a game instance to change screens. So updating player's entity components this way won't make much of a difference. There is however, the option of keeping an instance of player entity in the game area, access its combat stats component and check for the player health which allows us to change the screen from main. This function would need to be called in each render, increasing our over head and changing the paradigm from event driven to polling where we query the program at each frame. Other options include passing an instance of game to the player and to the component which handles death display actions or creating a component in the main screen which takes game as a component and passing that component through and adding it to player eventually. Previously, this feature was implemented by passing the game through to ForrestGameArea and then the player. However, this implementation as UI component rather than a screen did not end the game and also required passing the GDXGame instance through multiple classes which undermined principles of OOP design. Therefore, the implementation was changed to the polling method instead which did not affect the performance of the game to a noticeable degree.

Improvments

Currently the death screen background, is the background of the game, since adding a background to the DeathDisplay UI component caused the animation in the death screen to not be displayed. This may cause some scaling issues as the animation and other parts of the death display such as the title scale differently when the window size changes. Further improvement may include combining a background and title with the animation for one animation component that can be displayed under the buttons and readjusted all together as the screen size changes.

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