]> git.localhorst.tv Git - l2e.git/commitdiff
added numbers animation for monsters' attacks
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 20 Aug 2012 20:35:58 +0000 (22:35 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 20 Aug 2012 20:38:27 +0000 (22:38 +0200)
src/battle/BattleState.h
src/battle/states/PerformAttacks.cpp
src/battle/states/PerformAttacks.h

index 8814663dae807fce9eb3226b065e60e889fdc7bb..a10ff7e8fae2b6947dd651c4a403c9b33c57e76d 100644 (file)
@@ -76,6 +76,7 @@ public:
        virtual void UpdateWorld(float deltaT);
        virtual void Render(SDL_Surface *);
 
+       // TODO: turn this mess into a well stuctured interface
 public:
        const Resources &Res() const { return *res; }
        AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
@@ -108,6 +109,8 @@ public:
        const AttackChoice &ActiveHeroAttackChoice() const { return AttackChoiceAt(activeHero); }
        AttackChoice &AttackChoiceAt(int index) { assert(index >= 0 && index < NumHeroes()); return attackChoices[index]; }
        const AttackChoice &AttackChoiceAt(int index) const { assert(index >= 0 && index < NumHeroes()); return attackChoices[index]; }
+       AttackChoice &MonsterAttackChoiceAt(int index) { assert(index >= 0 && index < MaxMonsters()); return monsterAttacks[index]; }
+       const AttackChoice &MonsterAttackChoiceAt(int index) const { assert(index >= 0 && index < MaxMonsters()); return monsterAttacks[index]; }
        bool AttackSelectionDone() const { return activeHero >= numHeroes; }
 
        int NumHeroes() const { return numHeroes; }
index 10fb8bb11294c6f0f517d1def1efd528cbd86cbb..238849b3f5da06638e04925fe5311d246e6a7783 100644 (file)
@@ -75,7 +75,7 @@ void PerformAttacks::HandleEvents(const Input &input) {
                titleBarText = monster.Name();
                moveAnimation = monster.AttackAnimation();
                targetAnimation = monster.MeleeAnimation();
-               // TODO: add number animations
+               AddNumberAnimations(battle->MonsterAttackChoiceAt(battle->CurrentAttack().index).Selection());
        } else {
                Hero &hero(battle->HeroAt(battle->CurrentAttack().index));
                const AttackChoice &ac(battle->AttackChoiceAt(battle->CurrentAttack().index));
@@ -90,24 +90,7 @@ void PerformAttacks::HandleEvents(const Input &input) {
                                        targetAnimation = hero.MeleeAnimation();
                                }
                                moveAnimation = hero.AttackAnimation();
-
-                               if (ac.Selection().TargetsEnemies()) {
-                                       for (int i(0); i < battle->MaxMonsters(); ++i) {
-                                               if (ac.Selection().IsSelected(i)) {
-                                                       numberAnimation.push_back(NumberAnimation(ac.Selection().GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
-                                                       numberPosition.push_back(
-                                                                       battle->MonsterPositions()[i]);
-                                               }
-                                       }
-                               } else {
-                                       for (int i(0); i < battle->NumHeroes(); ++i) {
-                                               if (ac.Selection().IsSelected(i)) {
-                                                       numberAnimation.push_back(NumberAnimation(ac.Selection().GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
-                                                       numberPosition.push_back(
-                                                                       battle->HeroesPositions()[i]);
-                                               }
-                                       }
-                               }
+                               AddNumberAnimations(ac.Selection());
                                break;
                        case AttackChoice::MAGIC:
                                titleBarText = ac.GetSpell()->Name();
@@ -147,6 +130,34 @@ void PerformAttacks::HandleEvents(const Input &input) {
        }
 }
 
+void PerformAttacks::AddNumberAnimations(const TargetSelection &ts) {
+       if (ts.TargetsEnemies()) {
+               for (int i(0); i < battle->MaxMonsters(); ++i) {
+                       if (ts.IsBad(i)) {
+                               numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
+                               numberPosition.push_back(
+                                               battle->MonsterPositions()[i]);
+                       } else if (ts.IsGood(i)) {
+                               numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite));
+                               numberPosition.push_back(
+                                               battle->MonsterPositions()[i]);
+                       }
+               }
+       } else {
+               for (int i(0); i < battle->NumHeroes(); ++i) {
+                       if (ts.IsBad(i)) {
+                               numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
+                               numberPosition.push_back(
+                                               battle->HeroesPositions()[i]);
+                       } else if (ts.IsGood(i)) {
+                               numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite));
+                               numberPosition.push_back(
+                                               battle->HeroesPositions()[i]);
+                       }
+               }
+       }
+}
+
 void PerformAttacks::CheckAnimations() {
        if (targetAnimation && targetAnimationTimer.JustHit()) {
                targetAnimation->Start(*this);
index e8a878d761e6b214820ba998407c7d98087dc617..19e3200a42f2825504055ba1983d8fcffc1eeff6 100644 (file)
@@ -44,6 +44,8 @@ private:
        void ResetAnimation();
 
 private:
+       void AddNumberAnimations(const TargetSelection &);
+
        void RenderTitleBar(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
        void RenderNumbers(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
        void RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector<int> &offset) const;