From 9cfff98ffce0529c685fbd5aa52e213c295449a1 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 20 Aug 2012 23:41:10 +0200 Subject: [PATCH] adjusted PerformAttacks' usage of animations --- src/battle/states/PerformAttacks.cpp | 64 +++++++++++++++------------- src/battle/states/PerformAttacks.h | 6 +-- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index 36b7b16..15c4feb 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -27,6 +27,7 @@ using app::Application; using app::Input; using geometry::Point; using geometry::Vector; +using graphics::AnimationRunner; using std::vector; namespace battle { @@ -73,8 +74,9 @@ void PerformAttacks::HandleEvents(const Input &input) { if (battle->CurrentAttack().isMonster) { Monster &monster(battle->MonsterAt(battle->CurrentAttack().index)); titleBarText = monster.Name(); - moveAnimation = monster.AttackAnimation(); - targetAnimation = monster.MeleeAnimation(); + targetAnimation = AnimationRunner(monster.MeleeAnimation()); + moveAnimation = AnimationRunner(monster.AttackAnimation()); + monster.SetAnimation(moveAnimation); AddNumberAnimations(battle->MonsterAttackChoiceAt(battle->CurrentAttack().index).Selection()); } else { Hero &hero(battle->HeroAt(battle->CurrentAttack().index)); @@ -84,46 +86,47 @@ void PerformAttacks::HandleEvents(const Input &input) { case AttackChoice::SWORD: if (hero.HasWeapon()) { titleBarText = hero.Weapon()->Name(); - targetAnimation = hero.Weapon()->AttackAnimation(); + targetAnimation = AnimationRunner(hero.Weapon()->AttackAnimation()); } else { titleBarText = "Melee attack!"; - targetAnimation = hero.MeleeAnimation(); + targetAnimation = AnimationRunner(hero.MeleeAnimation()); } - moveAnimation = hero.AttackAnimation(); + moveAnimation = AnimationRunner(hero.AttackAnimation()); AddNumberAnimations(ac.Selection()); break; case AttackChoice::MAGIC: titleBarText = ac.GetSpell()->Name(); - moveAnimation = hero.SpellAnimation(); + moveAnimation = AnimationRunner(hero.SpellAnimation()); break; case AttackChoice::DEFEND: titleBarText = "Defends."; - moveAnimation = 0; + moveAnimation.Clear(); break; case AttackChoice::IKARI: if (ac.GetItem()->HasIkari()) { titleBarText = ac.GetItem()->GetIkari()->Name(); if (ac.GetItem()->GetIkari()->IsMagical()) { - moveAnimation = hero.SpellAnimation(); + moveAnimation = AnimationRunner(hero.SpellAnimation()); } else { - moveAnimation = hero.AttackAnimation(); + moveAnimation = AnimationRunner(hero.AttackAnimation()); } } break; case AttackChoice::ITEM: titleBarText = ac.GetItem()->Name(); - moveAnimation = 0; + moveAnimation.Clear(); break; case AttackChoice::UNDECIDED: titleBarText = "UNDECIDED"; - moveAnimation = 0; + moveAnimation.Clear(); break; } + hero.SetAnimation(moveAnimation); } if (titleBarText) titleBarTimer = GraphicsTimers().StartCountdown(850); - if (moveAnimation) moveAnimation->Start(*this); - if (targetAnimation) { + if (moveAnimation.Valid()) moveAnimation.Start(*this); + if (targetAnimation.Valid()) { targetAnimationTimer = GraphicsTimers().StartCountdown(150); } else { targetAnimationTimer.Clear(); @@ -159,14 +162,14 @@ void PerformAttacks::AddNumberAnimations(const TargetSelection &ts) { } void PerformAttacks::CheckAnimations() { - if (targetAnimation && targetAnimationTimer.JustHit()) { - targetAnimation->Start(*this); + if (targetAnimation.Valid() && targetAnimationTimer.JustHit()) { + targetAnimation.Start(*this); } - if (moveAnimation && !moveAnimation->Finished()) return; - if (targetAnimation && !targetAnimation->Finished()) return; - if (moveAnimation || targetAnimation) { - moveAnimation = 0; - targetAnimation = 0; + if (moveAnimation.Valid() && !moveAnimation.Finished()) return; + if (targetAnimation.Valid() && !targetAnimation.Finished()) return; + if (moveAnimation.Valid() || targetAnimation.Valid()) { + moveAnimation.Clear(); + targetAnimation.Clear(); for (vector::iterator i(numberAnimation.begin()), end(numberAnimation.end()); i != end; ++i) { i->Start(*this); } @@ -179,8 +182,8 @@ void PerformAttacks::CheckAnimations() { bool PerformAttacks::HasAnimationsRunning() const { if (titleBarTimer.Running()) return true; - if (moveAnimation && moveAnimation->Running()) return true; - if (targetAnimation && targetAnimation->Running()) return true; + if (moveAnimation.Valid() && moveAnimation.Running()) return true; + if (targetAnimation.Valid() && targetAnimation.Running()) return true; for (vector::const_iterator i(numberAnimation.begin()), end(numberAnimation.end()); i != end; ++i) { if (i->Running()) return true; } @@ -188,13 +191,14 @@ bool PerformAttacks::HasAnimationsRunning() const { } void PerformAttacks::ResetAnimation() { - if (moveAnimation) { - moveAnimation->Stop(); - moveAnimation = 0; + if (moveAnimation.Valid()) { + moveAnimation.Clear(); + if (!battle->CurrentAttack().isMonster) { + battle->HeroAt(battle->CurrentAttack().index).GetAnimation().Clear(); + } } - if (targetAnimation) { - targetAnimation->Stop(); - targetAnimation = 0; + if (targetAnimation.Valid()) { + targetAnimation.Clear(); } titleBarTimer.Clear(); numberAnimation.clear(); @@ -239,12 +243,12 @@ void PerformAttacks::RenderNumbers(SDL_Surface *screen, const Vector &offse } void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector &offset) const { - if (!targetAnimation || !targetAnimation->Running()) return; + if (!targetAnimation.Valid() || !targetAnimation.Running()) return; const TargetSelection &ts(battle->CurrentAttackAttackChoice().Selection()); const vector > &positions(ts.TargetsHeroes() ? battle->HeroesPositions() : battle->MonsterPositions()); for (vector >::size_type i(0), end(positions.size()); i < end; ++i) { if (ts.IsSelected(i)) { - targetAnimation->DrawCenter(screen, positions[i] + offset); + targetAnimation.DrawCenter(screen, positions[i] + offset); } } } diff --git a/src/battle/states/PerformAttacks.h b/src/battle/states/PerformAttacks.h index 19e3200..d060d5a 100644 --- a/src/battle/states/PerformAttacks.h +++ b/src/battle/states/PerformAttacks.h @@ -13,7 +13,7 @@ #include "../BattleState.h" #include "../NumberAnimation.h" #include "../../geometry/Vector.h" -#include "../../graphics/ComplexAnimation.h" +#include "../../graphics/Animation.h" #include @@ -53,8 +53,8 @@ private: private: app::Application *ctrl; BattleState *battle; - graphics::Animation *moveAnimation; - graphics::Animation *targetAnimation; + graphics::AnimationRunner moveAnimation; + graphics::AnimationRunner targetAnimation; const char *titleBarText; app::Timer titleBarTimer; app::Timer targetAnimationTimer; -- 2.39.2