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
WaterBossAnimationController
class
public class WaterBossAnimationController extends Component {
AnimationRenderComponent animator;
@Override
public void create() {
super.create();
animator = this.entity.getComponent(AnimationRenderComponent.class);
entity.getEvents().addListener("wanderLeft", this::animateWanderLeft);
entity.getEvents().addListener("wanderRight", this::animateWanderRight);
entity.getEvents().addListener("chaseLeft", this::animateChaseLeft);
entity.getEvents().addListener("chaseRight", this::animateChaseRight);
}
private void animateWanderLeft() {
animator.setFlipX(true);
animator.startAnimation("wander");
}
private void animateWanderRight() {
animator.setFlipX(false);
animator.startAnimation("wander");
}
private void animateChaseLeft() {
animator.setFlipX(true);
animator.startAnimation("chase");
}
private void animateChaseRight() {
animator.setFlipX(false);
animator.startAnimation("chase");
}
}
BossFactory
class
Used in public static Entity createWaterBossEntity(Entity target) {
Entity waterBoss = createBossNPC(target, Entity.EnemyType.WATER_BOSS);
BaseEnemyEntityConfig config = configs.waterBoss;
waterBoss.setEnemyType(Entity.EnemyType.WATER_BOSS);
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);
waterBoss
.addComponent(animator)
.addComponent(new WaterBossAnimationController());
waterBoss.getComponent(AnimationRenderComponent.class).scaleEntity();
waterBoss.scaleHeight(5.0f);
return waterBoss;
}
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