-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created the DroidAnimationController which listens to events relevant…
… to DroidTower's animations
- Loading branch information
1 parent
1863d80
commit 71e40d4
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
source/core/src/main/com/csse3200/game/components/tower/DroidAnimationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.csse3200.game.components.tower; | ||
|
||
import com.csse3200.game.components.Component; | ||
import com.csse3200.game.rendering.AnimationRenderComponent; | ||
|
||
/** | ||
* This class listens to events relevant to DroidTower entity's state and plays the animation when one | ||
* of the events is triggered. | ||
*/ | ||
public class DroidAnimationController extends Component { | ||
private AnimationRenderComponent animator; | ||
|
||
/** | ||
* Creation call for a DroidAnimationController, fetches the animationRenderComponent that this controller will | ||
* be attached to and registers all the event listeners required to trigger the animations and sounds. | ||
*/ | ||
@Override | ||
public void create() { | ||
super.create(); | ||
animator = this.entity.getComponent(AnimationRenderComponent.class); | ||
entity.getEvents().addListener("walkStart", this::animateWalk); | ||
entity.getEvents().addListener("idleStart", this::animateDefault); | ||
entity.getEvents().addListener("goUpStart",this::animateGoUp); | ||
entity.getEvents().addListener("goDownStart",this::animateGoDown); | ||
entity.getEvents().addListener("attackUpStart",this::animateAttackUp); | ||
entity.getEvents().addListener("attackDownStart",this::animateAttackDown); | ||
entity.getEvents().addListener("deathStart",this::animateDeath); | ||
|
||
} | ||
|
||
/** | ||
* Initiates the walking animation for the robot. | ||
* This method should be invoked when the robot is moving but not in combat. | ||
*/ | ||
void animateWalk() { | ||
animator.startAnimation("walk"); | ||
} | ||
|
||
/** | ||
* Starts the animation sequence for switching aim from above. | ||
* Use this method when the robot is preparing to target mobs after aiming from below. | ||
*/ | ||
void animateGoUp() { | ||
animator.startAnimation("goUp"); | ||
} | ||
|
||
/** | ||
* Activates the animation sequence for switching aim from below. | ||
* Use this method when the robot is preparing to target mobs after aiming from above. | ||
*/ | ||
void animateGoDown() { | ||
animator.startAnimation("goDown"); | ||
} | ||
|
||
/** | ||
* Triggers the animation for firing projectiles from an elevated aim. | ||
* Invoke this method when the robot engages with mobs and aiming above. | ||
*/ | ||
void animateAttackUp() { | ||
animator.startAnimation("attackUp"); | ||
} | ||
|
||
/** | ||
* Starts the animation sequence for firing projectiles from a lowered aim. | ||
* Use this method when the robot engages with mobs and aiming below. | ||
*/ | ||
void animateAttackDown() { | ||
animator.startAnimation("attackDown"); | ||
} | ||
|
||
/** | ||
* Triggers the robot's death animation. | ||
* This method should be invoked when the robot's health reaches zero. | ||
*/ | ||
void animateDeath() { | ||
animator.startAnimation("death"); | ||
} | ||
|
||
|
||
/** | ||
* Triggers the "default" animation for the entity. | ||
* This method should be invoked when the entity returns to its default state. | ||
*/ | ||
void animateDefault() { animator.startAnimation("default");} | ||
|
||
} |