Building animation - UQdeco2800/2022-studio-3 GitHub Wiki

Introduction

This page explains how building animations work, it includes the initial animation of the building, the animation when the building is half-healthy, the animation when the building is destroyed, and how the building is destroyed. It uses two components:

  • HealthAnimationComponent
  • BuildingAnimationControllerComponent

Implement

  1. HealthAnimationComponent The health status of the building is set. It sets three different health states for buildings, Normal, Half, Dead.
public String getAnimation() {
        if (health == Health.NORMAL) {
            return "100-idle";
        } else if (health == Health.HALF) {
            return "50";
        } else if (health == Health.DEAD) {
            return "collapse";
        }
        return null;
    }
  1. BuildingAnimationControllerComponent Get the health of the building from the HealthAnimation Component and start the animation, when the building's health is zero, the building will be destroyed.
void updateAnimation() {
        // Updates the health value in HealthComponent
        int health = this.entity.getComponent(CombatStatsComponent.class).getHealth();

        if (health <= D_health && health >= 0.5*D_health) {
            this.entity.getComponent(HealthAnimation.class).updateHealth(Health.NORMAL);
        } else if (health < 0.5*D_health && health > 0) {
            this.entity.getComponent(HealthAnimation.class).updateHealth(Health.HALF);
        } else if (health <= 0 && !dispose) {
            this.entity.getComponent(HealthAnimation.class).updateHealth(Health.DEAD);
            dispose = true;
        } else if (dispose) {
            this.entity.getComponent(PhysicsComponent.class).getPhysics().addToDestroy(this.entity);
        }
        // Applies the correct animation
        if (this.enabled) {
            animator.startAnimation(entity.getComponent(HealthAnimation.class).getAnimation());
        }
    }

UML

img