Skip to content

DroidAnimationController

Mohamad Dabboussi edited this page Sep 11, 2023 · 3 revisions

DroidAnimationController Documentation

Overview

The DroidAnimationController is a specialized game component designed to manage and trigger animations for the DroidTower entity. This class listens to a variety of events that correspond to different states of the DroidTower such as walking, aiming, attacking, and dying. The actual triggering of these events is managed by DroidCombatTask

How To Use It

To make use of the DroidAnimationController, you must first attach this component to a DroidTower entity. Below is a Java code snippet demonstrating this process:

DroidAnimationController animationController = new DroidAnimationController();
droidTowerEntity.addComponent(animationController);

Additionally, an AnimationRenderComponent is required for the controller to function. Here's how to add it:

private static final String DROID_ATLAS = "images/towers/DroidTower.atlas";
TextureAtlas textureAtlas = ServiceLocator.getResourceService().getAsset(DROID_ATLAS, TextureAtlas.class);
AnimationRenderComponent animator = new AnimationRenderComponent(textureAtlas);
droidTowerEntity.addComponent(animator);

Example Usage

General Event Listening Mechanism

The DroidAnimationController listens for events like "walkStart", "attackUpStart", "goDownStart", etc., which are triggered by other components. When an event is triggered, it initiates the corresponding animation on the DroidTower entity.

Here is the general way the controller listens for events:

entity.getEvents().addListener("<EventName>", this::<MethodName>);

Specific Event Examples

"idleStart" Event

  • Event Listener: this::animateDefault
  • Sprite Sheet: Single frame for the idle state

static idle

"walkStart" Event

  • Event Listener: this::animateWalk
  • Sprite Sheet: 6 frames for walking animation

walk

"goUpStart" and "goDownStart" Events

  • Event Listeners: this::animateGoUp and this::animateGoDown
  • Sprite Sheet: 10 frames in total for aiming up and down

gun to up position gun to down position

"attackUpStart" and "attackDownStart" Events

  • Event Listeners: this::animateAttackUp and this::animateAttackDown
  • Sprite Sheet: 11 frames in total for attacking animations while aiming up or down

attack high attack low

"deathStart" Event

  • Event Listener: this::animateDeath
  • Sprite Sheet: 9 frames for death animation

hit and death

Notes

  • The shooting logic is temporarily implemented within this component. In future releases, this functionality may be moved to a separate component that enables an entity to fire projectiles.

Best Practices

  • Ensure an AnimationRenderComponent is initialized and added to the entity before attaching DroidAnimationController.
  • Clearly specify your animation states in the AnimationRenderComponent for smooth transitions between animations.
  • Make sure the event names used in the combat logic component and DroidAnimationController are synchronized to maintain cohesive gameplay logic and animations.

Test Plan

Please refer to the DroidAnimationController Test Plan for detailed test cases and methodologies.

Clone this wiki locally