Animations for Land Boss - UQcsse3200/2024-studio-2 GitHub Wiki
Overview
The Kanga (Land) boss is an enemy in the game with animations reflecting two primary states:
- Wander Animation: The Kanga idly moves within its territory when not engaged with the player.
- Chase Animation: The Kanga aggressively chases the player.
Kanga boss also has the special ability to spawn little Joeys to attack the player.
Implementation
KangaBossAnimationController
class
public class KangaBossAnimationController 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 createKangaBossEntity(Entity target) {
Entity kangarooBoss = createBossNPC(target, Entity.EnemyType.KANGAROO);
BaseEnemyEntityConfig config = configs.kangarooBoss;
kangarooBoss.setEnemyType(Entity.EnemyType.KANGAROO);
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);
kangarooBoss.addComponent(animator)
.addComponent(new KangaBossAnimationController());
kangarooBoss.getComponent(AnimationRenderComponent.class).scaleEntity();
kangarooBoss.scaleHeight(4.0f);
return kangarooBoss;
}
JoeyAnimationController
public class JoeyAnimationController extends Component {
AnimationRenderComponent animator;
@Override
public void create() {
super.create();
// Get the AnimationRenderComponent associated with the entity and store it in the animator field
animator = this.entity.getComponent(AnimationRenderComponent.class);
entity.getEvents().addListener("spawnStart", this::animateSpawn);
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 animateSpawn() {
animator.startAnimation("spawn");
}
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");
}
}
EnemyFactory
class
Used in public static Entity createJoey(Entity target) {
Entity joey = createBaseEnemy(target, EnemyType.JOEY);
BaseEnemyEntityConfig config = configs.joey;
joey.setEnemyType(Entity.EnemyType.JOEY);
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);
animator.addAnimation("spawn", 1.0f, Animation.PlayMode.NORMAL);
joey.addComponent(animator)
.addComponent(new JoeyAnimationController());
joey.getComponent(AnimationRenderComponent.class).scaleEntity();
return joey;
}
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 Kanga Boss and its ability to spawn Joeys, a video recording was created to ensure the following aspects are functioning as intended:
-
Wander Animation (Kanga): The Kanga boss idly roams its designated territory when not engaged with the player, with correct left and right flipping depending on its movement direction.
-
Chase Animation (Kanga): When the player is detected, the Kanga boss transitions into a chase animation. The boss correctly flips its orientation based on the direction of movement, and the animation runs smoothly with no visible glitches.
-
Joey Spawn Animation: The special ability of the Kanga boss allows it to spawn Joeys to attack the player. This animation plays correctly during the spawn event, ensuring that the Joey appears as expected in the game environment.
-
Joey Wander Animation: After being spawned, Joeys idle or wander around the area when not directly engaging the player. The wander animation plays smoothly, including the left and right directional flips based on movement.
-
Joey Chase Animation: Like the Kanga boss, Joeys also have a chase animation when they pursue the player. The video demonstrates the smooth transition from idle to chase, with correct orientation based on direction.
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 show that the Boss Factory and related systems have a 76.4% code coverage, focusing primarily on the logic and functionality of the Kanga and Joey entities. The remaining 23.6% of the code is primarily related to visual rendering, which cannot be covered by standard unit tests and is instead verified through the visual testing described above.
Code Coverage Summary:
- Line Coverage: 76.0% - This measures how much of the executable code has been tested. Uncovered lines are mainly tied to graphical rendering, where visual confirmation is more reliable than automated testing.
Bugs and Vulnerabilities:
- Bugs: 0 - No bugs have been identified in the code.
- Vulnerabilities: 0 - No security vulnerabilities were detected, ensuring the system is secure.
Maintainability:
- Code Smells: 7 - These refer to areas in the code that could be improved for readability, maintainability, or efficiency. However, they do not negatively impact the performance or functionality of the game.
UML Diagram
Sequence Diagram