Character Corpse - UQcsse3200/2024-studio-1 GitHub Wiki

Character Corpse

Objectives

The objective of this task is to display the corpse image upon the character death in order to align with the game design brief and create a consistent game story. Upon receiving the event of character death, the corpse image should be rendered in place of the character.

Implementation Details

DeathPlayerAnimation class

The DeathPlayerAnimation class has been implemented for drawing the corpse, which extends from the UIComponent. This utilises the draw function to size the image appropriately and obtains the current position of the character on the game screen, to render it in the same location. In order to start the draw two conditions must be achieved, which is the entity.getComponent(CombatStatsComponent.class).isDead() and the entity.getComponent(PlayerAnimationController.class).stopAnimation(). This ensures the player health has reached zero and the death animation has finished before the corpse gets displayed.

PlayerActions and PlayerAnimationController class

Primarily for the player corpse, the PlayerActions class has been updated to include the necessary event triggers for the PlayerAnimationController class to handle. The following logic was implemented to trigger the death and stop animation, in which a boolean value is set to ensure the death is only triggered once.

if (entity.getComponent(CombatStatsComponent.class).isDead()) {
  entity.getEvents().trigger("stopAnimation");
    if (!dead) {
      entity.getEvents().trigger("death");
      dead = true;
    }
}

The PlayerAnimationController class then handles these triggers by starting the death animation, and upon completion of the animation, removes the character from the screen to allow the corpse to be rendered.

PlayerFactory class

This is an existing class that creates the player entity. In regard to the player corpse, a DeathPlayerAnimation object has been added, which is used to control the rendering of the player corpse.

Example of this on GUI

The following is the character's animation in the idle state:

image

UML Diagram

An overview of the DeathPlayerAnimation is summarised in the UML diagram below.

DeathPlayerAnimation

Sequence Diagram

An overview of the DeathPlayerAnimation draw function is summarised in the Sequence diagram below.

DeathPlayerAnimationSEQUENCE

Usage

The necessary image should be contained within a png file in the assets directory for easy referral within the DeathPlayerAnimation class. The following is an example of how to set up the DeathPlayerAnimation.

Entity entity = new Entity();
entity.addComponent(new DeathPlayerAnimation());

Sample Testing

Linked below is the sample of the corpse animation working.

PLayer.Corpse.Test.mp4

References

Below is the citation for the use of the corpse asset.

Premium vector: Pixel art of corpse bag murder (no date) Freepik. Available at: https://www.freepik.com/premium-vector/pixel-art-corpse-bag-murder_62566011.htm (Accessed: 11 August 2024).

⚠️ **GitHub.com Fallback** ⚠️