Animations for Air Boss - UQcsse3200/2024-studio-2 GitHub Wiki

Overview

The Griffin (Air) boss is an enemy in the game with animations reflecting it flying:

Gust of Wind, which Griffin shoots toward player while flying away.

Implementation

AirBossAnimationController class

public class AirBossAnimationController 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");
    }
}

Used in BossFactory class

public static Entity createAirBossEntity(Entity target) {
        Entity airBoss = createBossNPC(target, Entity.EnemyType.AIR_BOSS);
        BaseEnemyEntityConfig config = configs.airBoss;
        airBoss.setEnemyType(Entity.EnemyType.AIR_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);

        airBoss
                .addComponent(animator)
                .addComponent(new AirBossAnimationController());

        airBoss.getComponent(AnimationRenderComponent.class).scaleEntity();
        airBoss.scaleHeight(6.0f);

        return airBoss;
    }

WindGustAnimationController class

public class WindGustAnimationController 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("windGust");
    }
}

Used in ProjectileFactory class

public static Entity createWindGust(Entity target) {
    Entity windGust = createBaseProjectile(target);
    BaseEnemyEntityConfig config = configs.windGust;

    AITaskComponent aiTaskComponent = new AITaskComponent();
    aiTaskComponent.addTask(new ProjectileMovementTask(target, 10));

    windGust.addComponent(aiTaskComponent);

    TextureAtlas windGustAtlas = ServiceLocator.getResourceService().getAsset(config.getSpritePath(), TextureAtlas.class);

    AnimationRenderComponent animator = new AnimationRenderComponent(windGustAtlas);
    animator.addAnimation("windGust", 0.1f, Animation.PlayMode.LOOP);

    windGust
            .addComponent(animator)
            .addComponent(new WindGustAnimationController());
    windGust.setScale(5.0f, 5.0f);

    windGust.getComponent(PhysicsMovementComponent.class).changeMaxSpeed(new Vector2(config.getSpeed(), config.getSpeed()));

    return windGust;
  }

Testing Plan

Visual Testing - https://youtu.be/yU9CXT3zjS0

https://github.com/user-attachments/assets/8cd3d9bb-1fea-43e9-b8b3-2c146fc2736d

For visual confirmation of the animations and behaviour of the Griffin (Air Boss) and its Wind Gust projectile, a video recording was created to ensure the following aspects are functioning as intended:

  1. Wander Animation (Griffin): The Griffin boss flies around its designated area when not engaged with the player. The animation smoothly reflects its wandering state, with correct left and right flipping depending on the direction of its movement.

  2. Chase Animation (Griffin): When the player is detected, the Griffin boss transitions into a chase animation. The animation runs smoothly, with the boss flipping its orientation based on the direction it is chasing, ensuring there are no visible glitches.

  3. Wind Gust Animation: The special ability of the Griffin allows it to shoot a gust of wind toward the player while flying. This animation was confirmed to play correctly, with the projectile following a smooth and accurate trajectory toward the player.

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 for the Griffin boss have 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 visual rendering of animations and effects, which have been verified through the visual testing mentioned above.

Code Coverage Summary:

  • Line Coverage: 76.0% — This measures how much of the executable code has been tested. The uncovered lines are primarily related to graphical rendering, which is better tested visually rather than through automation.

Bugs and Vulnerabilities:

  • Bugs: 0 — No bugs were identified in the code.
  • Vulnerabilities: 0 — No security vulnerabilities were detected, ensuring that the system is secure and reliable.

Maintainability:

  • Code Smells: 7 — These refer to minor inefficiencies in the code that could be improved for better readability and maintainability. However, none of these affect the performance or functionality of the game.

UML Diagram

Sequence Diagram

AirBossAnimationController_create WindGustAnimationController_create

Class Diagram

airAnimation