Character Animations - UQcsse3200/2024-studio-1 GitHub Wiki
The objective of this task is to display the character and provide visual feedback in the form of animations to create a realistic game environment. Upon receiving events that affect the character, the corresponding animation should start. The end goal is to have multiple animations for the main character that play during relevant events, such as walking, running, jumping, attacks and death. For sprint 1, the animation for the character walking in the four directions (Up, Down, Left and Right) has been implemented as well as the idle/stationary animation. For sprint 2, this has been updated to play the damage animation and the death animation. For sprint 3, this has been updated to accommodate new characters and their animations, also adding sounds to alert players when they take damage.
The PlayerAnimationController
class has been implemented for handling every player and their animations. This helps organise and manage every animation relevant to the player. The class is used to listen and respond to the triggered events, by starting or stopping the relevant animations.
This class is an existing input handler for keyboard and touch input.
Primarily for the player animation, this class has been updated to include the necessary event triggers for the PlayerAnimationController
class to handle. The function getDirection(Vector2 vector)
was implemented to convert the Vector2
direction to a simplified String
for easy referral. This is then used in the triggerWalkEvent()
function, which has been updated to trigger "walkLeft", "walkUp", "walkRight" and "walkDown" events upon receiving the walkDirection.
This is an existing class that loads the player entity.
Regarding the player animation, a AnimationRenderComponent
object has been added, which is used to add all the player animations from the relevant player atlas file. This provides the player entity with all the animations, which the PlayerAnimationController
class then controls. In Sprint 3, this class added a method to load the sounds that required for alerting when players attacked.
This is an existing class that handles Player actions. PlayerActions class has been updated to include the death 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 handles these triggers by starting the death animation, and upon completion of the death animation, removes the character from the screen to allow the corpse to be rendered.
CombatStatsComponent class has been updated to include the damage event triggers for the PlayerAnimationController class to handle. Upon receiving a hit within the hit function, the "playerHit" trigger is called.
The UML diagram for the updated PlayerAnimationController
An overview of how the PlayerAnimationController interacts with the other classes is summarised in the UML diagram below.
The sequence diagram for the walkLeft() and the create() function in PlayerAnimationController are summarised below.
The player animation should be contained within a png file, and the associated atlas file needs to be generated.
Note: To set up the animations, refer to Animations.
The following is an example of how the walk left animation is set up.
The "walk-left" animation needs to be added to the player factory. Since walking is a repeated animation, the PlayMode is set to LOOP.
animator.addAnimation("walk-left", 0.2f, Animation.PlayMode.LOOP);
To prompt a change in animation, an event needs to be triggered. In this case, the walk left animation is triggered upon receiving the walkDirection
in the triggerWalkEvent()
function.
event.getEvents().trigger("walkLeft");
Listen for the walk left event and start the animation.
entity.getEvents().addListener("walkLeft", this::walkLeft);
void walkLeft() { animationController.startAnimation("walk-left"); }
Linked below is the sample testing of the working of the player walking in-game.
Player.Animation.Test.mp4
Linked below is the sample testing of the working of the player damage and death in-game.
Player.Animation.Test.Sprint.2.mp4
Linked below is the sample testing of the working of the player and new player animations in-game.
Screen.Recording.2024-10-02.092306.mp4
Manual UI Testing Plan
Objective: To verify the animation is working for each character during in-game scenarios.
Scenario 1: Walk-direction triggers play the correct animation
- Task: Start the game and use the keys to move the player in different directions.
- Expected Outcome: The player animation associated with the correct walk direction should start.
Scenario 2: Damage triggers play the correct animation
- Task: Start the game and move towards the enemies, letting them attack you.
- Expected Outcome: The player animation associated with the damage trigger should start.
Scenario 3: Idle triggers play the correct animation
- Task: Start the game and use the keys to move the player in different directions, then stop.
- Expected Outcome: When no triggers are received, the idle animations should be playing.
Scenario 4: Death triggers play the correct animation
- Task: Start the game and move towards the enemies, letting them attack you until health reaches 0.
- Expected Outcome: The death animation should play, and the corpse then displayed.
Scenario 5: Animation works throughout each level
- Task: Start the game and progress through levels.
- Expected Outcome: The desired animations should play throughout the game.
Scenario 6: Animation works when multiple triggers are sent
- Task: Start the game and walk towards an enemy, letting them attack.
- Expected Outcome: The walk animation and damage animation should play.
Below is the citation for the use of the assets.
Bagong Games: Hana Caraka - base character by Bagong Games, itch.io. (5 March 2024)
Available at: https://bagong-games.itch.io/hana-caraka-base-character (Accessed: 20 August 2024).
Free Homeless Pixel Sprite Sheets, itch.io.
Available at: https://free-game-assets.itch.io/free-homeless-character-sprite-sheets-pixel-art (Accessed: 20 September 2024).
20110302_ouch.ogg, freesound.
Available at: https://freesound.org/people/DanielCraig909/sounds/496904/
bell.ogg, freesound.
Available at: https://freesound.org/people/passllooll/sounds/557282/
Hit Impact, freesound.
Available at: https://freesound.org/people/MadPanCake/sounds/660770/
Tossing a thing at someone.
Available at: https://freesound.org/people/pfranzen/sounds/321505/