]> git.localhorst.tv Git - l2e.git/commitdiff
adjusted PerformAttacks' usage of animations
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 20 Aug 2012 21:41:10 +0000 (23:41 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 20 Aug 2012 21:41:10 +0000 (23:41 +0200)
src/battle/states/PerformAttacks.cpp
src/battle/states/PerformAttacks.h

index 36b7b1630d41477fa23ba7055ed629ee39078a8c..15c4feba5ab0633cd0acf638ebc1aa0ea2b28d3e 100644 (file)
@@ -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<NumberAnimation>::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<NumberAnimation>::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<int> &offse
 }
 
 void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
-       if (!targetAnimation || !targetAnimation->Running()) return;
+       if (!targetAnimation.Valid() || !targetAnimation.Running()) return;
        const TargetSelection &ts(battle->CurrentAttackAttackChoice().Selection());
        const vector<Point<int> > &positions(ts.TargetsHeroes() ? battle->HeroesPositions() : battle->MonsterPositions());
        for (vector<Point<int> >::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);
                }
        }
 }
index 19e3200a42f2825504055ba1983d8fcffc1eeff6..d060d5a55f38406ed6f0fa11e721fba8569447ad 100644 (file)
@@ -13,7 +13,7 @@
 #include "../BattleState.h"
 #include "../NumberAnimation.h"
 #include "../../geometry/Vector.h"
-#include "../../graphics/ComplexAnimation.h"
+#include "../../graphics/Animation.h"
 
 #include <vector>
 
@@ -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<Uint32> titleBarTimer;
        app::Timer<Uint32> targetAnimationTimer;