Animations for Water Boss - UQcsse3200/2024-studio-2 GitHub Wiki
Overview
The Leviathan (Water) boss is an enemy in the game with animations reflecting four primary states:
- Wander Animation: The Leviathan idly moves within its territory when not engaged with the player.
- Chase Animation: The Leviathan aggressively chases the player.
Water Spiral animation, which Leviathan shoots toward the player.
Implementation
BossAnimationController
class
/**
* This class listens to events related to the Boss entity's state and plays the appropriate animation
* when one of the events is triggered. The Boss has animations for wandering and chasing in both the
* left and right directions.
*/
public class BossAnimationController extends Component {
// Animation render component responsible for playing animations
private AnimationRenderComponent animator;
/**
* Called when the component is created. Sets up listeners for the Boss movement events
* and links them to corresponding animation triggers.
*/
@Override
public void create() {
super.create();
// Retrieves the AnimationRenderComponent from the entity
animator = this.entity.getComponent(AnimationRenderComponent.class);
// Set up listeners for movement-related events and assign appropriate animations
entity.getEvents().addListener("wanderLeft", this::animateWanderLeft);
entity.getEvents().addListener("wanderRight", this::animateWanderRight);
entity.getEvents().addListener("chaseLeft", this::animateChaseLeft);
entity.getEvents().addListener("chaseRight", this::animateChaseRight);
}
/**
* Plays the wander animation with the entity facing left by flipping the animation on the X-axis.
*/
private void animateWanderLeft() {
animator.setFlipX(true);
animator.startAnimation("wander");
}
/**
* Plays the wander animation with the entity facing right (default direction).
*/
private void animateWanderRight() {
animator.setFlipX(false);
animator.startAnimation("wander");
}
/**
* Plays the chase animation with the entity facing left by flipping the animation on the X-axis.
*/
private void animateChaseLeft() {
animator.setFlipX(true);
animator.startAnimation("chase");
}
/**
* Plays the chase animation with the entity facing right (default direction).
*/
private void animateChaseRight() {
animator.setFlipX(false);
animator.startAnimation("chase");
}
}
BossFactory
class
Used in /**
* Creates a boss NPC to be used as a boss entity by more specific NPC creation methods.
*
* @param target the entity to chase
* @param type the type of the boss
* @return entity
*/
public static Entity createBossNPC(Entity target, Entity.EnemyType type, BaseEnemyEntityConfig config) {
AnimationRenderComponent animator =
new AnimationRenderComponent(
ServiceLocator.getResourceService().getAsset(config.getSpritePath(), TextureAtlas.class));
animator.addAnimation("wander", 0.1f, Animation.PlayMode.LOOP);
animator.addAnimation("chase", 0.1f, Animation.PlayMode.LOOP);
Entity npc = new Entity()
.addComponent(animator)
.addComponent(new BossAnimationController());
return npc;
}
WaterSpiralAnimationController
class
public class WaterSpiralAnimationController extends Component {
AnimationRenderComponent animator;
@Override
public void create() {
super.create();
animator = this.entity.getComponent(AnimationRenderComponent.class);
entity.getEvents().addListener("ProjectileMove", this::animateWaterSpiral);
}
private void animateWaterSpiral() {
animator.startAnimation("waterSpiral");
}
}
ProjectileFactory
class
Used in public static Entity createWaterSpiral(Entity target) {
Entity waterSpiral = createBaseProjectile(target);
BaseEnemyEntityConfig config = configs.waterSpiral;
AITaskComponent aiTaskComponent = new AITaskComponent();
aiTaskComponent.addTask(new ProjectileMovementTask(target, 10));
waterSpiral.addComponent(aiTaskComponent);
TextureAtlas waterSpiralAtlas = ServiceLocator.getResourceService().getAsset(config.getSpritePath(), TextureAtlas.class);
AnimationRenderComponent animator = new AnimationRenderComponent(waterSpiralAtlas);
animator.addAnimation("waterSpiral", 0.1f, Animation.PlayMode.LOOP);
waterSpiral
.addComponent(animator)
.addComponent(new WaterSpiralAnimationController());
waterSpiral.setScale(3.0f, 3.0f);
waterSpiral.getComponent(PhysicsMovementComponent.class).changeMaxSpeed(new Vector2(config.getSpeed(), config.getSpeed()));
return waterSpiral;
}
Testing Plan
https://youtu.be/yU9CXT3zjS0
Visual Testing -https://github.com/user-attachments/assets/8cd3d9bb-1fea-43e9-b8b3-2c146fc2736d
For visual confirmation of the animations and behaviour of the Leviathan (Water Boss) and its Water Spiral projectile, a video recording was created to ensure the following aspects are functioning as intended:
- Wander Animation: The Leviathan smoothly moves in a passive state when it is not engaged with the player, with correct left and right flipping based on direction.
- Chase Animation: The Leviathan transitions seamlessly into a chase animation when pursuing the player. This includes correct directional flipping and no glitches in movement or animation timing.
- Water Spiral Animation: The Water Spiral projectile is triggered and follows the correct trajectory toward the player, with smooth looping of the spiral animation until it reaches its target or expiration.
All these animations were visually confirmed in the gameplay environment and documented through the video above. This method of visual testing compensates for the limitations of automated testing in areas of graphical rendering, ensuring that the animations behave as expected in a live game scenario.
Code Coverage & Reliability Report
The automated testing results indicate that the Boss Factory has a 76.4% code coverage, focusing primarily on logic and functionality. The remaining 23.6% of the code, which is not covered by tests, mainly deals with the rendering of animations and real-time visual effects, which were covered through the visual testing described above.
Code Coverage Summary:
- Line Coverage: 76.0% - This measures the percentage of executable lines in the code that have been tested. The uncovered lines mostly involve rendering logic where automated tests are less effective.
Bugs and Vulnerabilities:
- Bugs: 0 - No bugs were identified in the code.
- Vulnerabilities: 0 - No security issues were detected, ensuring the integrity of the system remains uncompromised.
Maintainability:
- Code Smells: 7 - These refer to the structural inefficiencies in the code that could be improved for readability or simplicity. However, none of these have a direct impact on the current performance or functionality.
UML Diagram
Sequence Diagram