Combat Animations - UQcsse3200/2024-studio-2 GitHub Wiki
The CombatAnimationDisplay
class manages and implements animations for both players and enemies during combat. It extends UIComponent
to add images to an invisible stage over the Combat Screen, providing a visual representation of combat actions.
The CombatAnimationDisplay
is instantiated in the CombatManager
class, which handles combat logic:
private final CombatAnimationDisplay combatAnimationDisplay = new CombatAnimationDisplay();
Animations are triggered through the animateCombat
method, which takes into account both player and enemy actions, as well as which entity is faster:
combatAnimationDisplay.animateCombat(playerAction, enemyAction, playerIsFaster);
This method determines the order and timing of animations based on player and enemy actions:
public void animateCombat(CombatManager.Action playerAction, CombatManager.Action enemyAction, Boolean playerFaster) {
if (playerAction == CombatManager.Action.ATTACK || enemyAction == CombatManager.Action.ATTACK) {
if (playerAction == enemyAction && playerFaster) {
initiatePlayerAnimation(playerAction);
Timer.schedule(new Timer.Task() {
@Override
public void run() {
initiateEnemyAnimation(enemyAction);
}
}, bothAttackAnimationDelay);
return;
}
// ... (other conditions)
}
// ... (other logic)
}
These methods trigger the appropriate animation based on the action:
public void initiatePlayerAnimation(CombatManager.Action animationType) {
create();
if (animationType == CombatManager.Action.ATTACK) {
playerAttackAnimation();
} else if (animationType == CombatManager.Action.GUARD) {
guardAnimation();
} else if (animationType == CombatManager.Action.SLEEP) {
sleepAnimation();
}
}
-
playerAttackAnimation()
: Animates a rock moving from player to enemy. -
enemyAttackAnimation()
: Animates a rock moving from enemy to player. -
sleepAnimation()
: Displays "zzz" above the sleeping entity. -
guardAnimation()
: Shows a shield for the guarding entity.
Move | Animation Image | Description |
---|---|---|
Attack | The attack animation is a rock being thrown, as rocks can be seen anywhere in the world and can be easily utilised by animals to fight each other. | |
Sleep | The Z's animation is used as it is universal when related to sleep, and matches the brighter aesthetic of the game, calming down the potentially dark nature of combat. | |
Guard | The shield animation is used for guarding as a shield is usually what is associated when protecting one's self. |
- Use of
Timer
andTimer.Task
for timed animations independent of combat logic speed. - Adaptation to different kingdom types (e.g., WATER) for positioning animations.
- Scaling of animations based on stage dimensions for consistency across different screen sizes.
classDiagram
UIComponent <|-- CombatAnimationDisplay
CombatAnimationDisplay : -Image combatImage
CombatAnimationDisplay : -Image guardImage
CombatAnimationDisplay : -Image sleepImage
CombatAnimationDisplay : -Image enemyCombatImage
CombatAnimationDisplay : -Image enemySleepImage
CombatAnimationDisplay : -Image enemyGuardImage
CombatAnimationDisplay : +animateCombat(playerAction, enemyAction, playerFaster)
CombatAnimationDisplay : +initiatePlayerAnimation(animationType)
CombatAnimationDisplay : +initiateEnemyAnimation(animationType)
CombatAnimationDisplay : -playerAttackAnimation()
CombatAnimationDisplay : -enemyAttackAnimation()
CombatAnimationDisplay : -sleepAnimation()
CombatAnimationDisplay : -guardAnimation()
CombatAnimationDisplay : +dispose()
sequenceDiagram
participant CM as CombatManager
participant CAD as CombatAnimationDisplay
participant Timer
CM->>CAD: animateCombat(playerAction, enemyAction, playerFaster)
alt playerAttack
CAD->>CAD: initiatePlayerAnimation(ATTACK)
CAD->>CAD: playerAttackAnimation()
CAD->>Timer: schedule(enemyAnimation)
else enemyAttack
CAD->>CAD: initiateEnemyAnimation(ATTACK)
CAD->>CAD: enemyAttackAnimation()
else playerGuard
CAD->>CAD: initiatePlayerAnimation(GUARD)
CAD->>CAD: guardAnimation()
else playerSleep
CAD->>CAD: initiatePlayerAnimation(SLEEP)
CAD->>CAD: sleepAnimation()
end
Timer-->>CAD: run scheduled animation