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. Four characters have been implemented, a default and three 'homeless' human characters. An option to choose a bear has been added (see Animals). Each character has multiple animations, such as stationary, walking, damage, attacks and death that play during relevant event triggers. The base character (default) has animations in the four directions (Up, Down, Left and Right), whereas the three human characters has two directions (Left, Right). These have been utilized so that the following animations play in a continuous manner. To provide auditory feedback to players, sounds have been added when a character takes 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 also manages directional animations, ensuring any following animations are triggered in the direction of the previous animation.
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. This class also has a method to load the sounds that are played upon an attack to the character.
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 "walk left" character animation is summarised below. This includes the create() and walkLeft() function in PlayerAnimationController.
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 two different sample testing of all the player animations in-game.
Sprint.3.Testing.mp4
Sprint.4.Testing.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.
Scenario 7: Directional animations
- Task: Start the game and walk in a different direction and stop walking.
- Expected Outcome: The idle animation should start playing in the same direction
- Additional Task: Get damage, attack and die in-game
- Expected Outcome: The damage and death animations should be in the same direction as previous movement.
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/