From d2f44bfe5d159647431cee8ab29898bd3618d980 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 20 Aug 2012 22:35:58 +0200 Subject: [PATCH] added numbers animation for monsters' attacks --- src/battle/BattleState.h | 3 ++ src/battle/states/PerformAttacks.cpp | 49 +++++++++++++++++----------- src/battle/states/PerformAttacks.h | 2 ++ 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 8814663..a10ff7e 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -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; } diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index 10fb8bb..238849b 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -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); diff --git a/src/battle/states/PerformAttacks.h b/src/battle/states/PerformAttacks.h index e8a878d..19e3200 100644 --- a/src/battle/states/PerformAttacks.h +++ b/src/battle/states/PerformAttacks.h @@ -44,6 +44,8 @@ private: void ResetAnimation(); private: + void AddNumberAnimations(const TargetSelection &); + void RenderTitleBar(SDL_Surface *screen, const geometry::Vector &offset) const; void RenderNumbers(SDL_Surface *screen, const geometry::Vector &offset) const; void RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector &offset) const; -- 2.39.2