Skip to content

Building animation

DLAmeng edited this page Oct 16, 2022 · 4 revisions

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

Table of Contents

Home

Game

Game Home

Design Influences

Gameplay Features

Style

Story

Friendly Units
Map
City
Buildings
Unit Selections

Spell

Game User Testing: Theme of Unit Selection & Spell System

UI User Testing

Tutorial

Resource Stats Display

Loading Screen Bar

Health Bars
In Game menu
  • Feature
  • User Testing:In Game Menu

Landscape Tile Design

Landscape Tile Design Feedback

Weather Design

Weather Design Feedback

Camera Movement

Enemy design

Enemy Units

Enemy AI

How Animation Works

Map Flooding

Game Engine

Getting Started

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally