From: Daniel Karbach Date: Tue, 21 Aug 2012 20:15:08 +0000 (+0200) Subject: moved hero position to Hero X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=cded7d136b41e22f363ec702f2288491c0006e3a;p=l2e.git moved hero position to Hero --- diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index 649470e..aae4635 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -79,8 +79,8 @@ void BattleState::Resize(int w, int h) { void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) { monstersLayout->CalculatePositions(background->w, background->h, monsterPositions); - heroesLayout->CalculatePositions(background->w, background->h, heroesPositions); for (int i(0); i < 4; ++i) { + heroes[i].Position() = heroesLayout->CalculatePosition(i, background->w, background->h); heroes[i].SpellMenu() = res->spellMenuPrototype; heroes[i].UpdateSpellMenu(); heroes[i].IkariMenu() = res->ikariMenuPrototype; @@ -381,10 +381,10 @@ void BattleState::RenderHeroes(SDL_Surface *screen, const Vector &offset) { assert(screen); for (int i(0); i < numHeroes; ++i) { if (heroes[i].GetAnimation().Running()) { - heroes[i].GetAnimation().DrawCenter(screen, heroesPositions[i] + offset); + heroes[i].GetAnimation().DrawCenter(screen, heroes[i].Position() + offset); } else { int row(heroes[i].Health() > 0 ? 0 : 2); - heroes[i].Sprite()->DrawCenter(screen, heroesPositions[i] + offset, 1, row); + heroes[i].Sprite()->DrawCenter(screen, heroes[i].Position() + offset, 1, row); } } } diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 4a07f8e..f5268dd 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -111,7 +111,6 @@ public: const std::vector > &MonsterPositions() const { return monsterPositions; } bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; } - const std::vector > &HeroesPositions() const { return heroesPositions; } bool HeroPositionOccupied(int index) const { return index >= 0 && index < numHeroes; } void SetRunaway() { ranAway = true; } @@ -164,7 +163,6 @@ private: MoveMenu moveMenu; // TODO: combine all data about heros or monsters std::vector > monsterPositions; - std::vector > heroesPositions; std::vector monsters; std::vector attackOrder; Hero heroes[4]; diff --git a/src/battle/Hero.h b/src/battle/Hero.h index 44d0b4d..7444902 100644 --- a/src/battle/Hero.h +++ b/src/battle/Hero.h @@ -10,6 +10,7 @@ #include "AttackChoice.h" #include "Stats.h" +#include "../geometry/Point.h" #include "../graphics/Animation.h" #include "../graphics/Menu.h" @@ -87,6 +88,9 @@ public: const graphics::Animation *AttackAnimation() const { return attackAnimation; } const graphics::Animation *SpellAnimation() const { return spellAnimation; } + geometry::Point &Position() { return position; } + const geometry::Point &Position() const { return position; } + graphics::Menu &SpellMenu() { return spellMenu; } const graphics::Menu &SpellMenu() const { return spellMenu; } graphics::Menu &IkariMenu() { return ikariMenu; } @@ -143,6 +147,8 @@ private: graphics::AnimationRunner animation; + geometry::Point position; + graphics::Menu spellMenu; graphics::Menu ikariMenu; diff --git a/src/battle/PartyLayout.h b/src/battle/PartyLayout.h index d16f2bd..6844139 100644 --- a/src/battle/PartyLayout.h +++ b/src/battle/PartyLayout.h @@ -10,6 +10,7 @@ #include "../geometry/Point.h" +#include #include #include @@ -33,6 +34,14 @@ public: )); } } + template + geometry::Point CalculatePosition(std::vector >::size_type index, U width, U height) const { + assert(index >= 0 && index < positions.size()); + return geometry::Point( + positions[index].X() * width / 255, + positions[index].Y() * height / 223 + ); + } public: void AddPosition(const geometry::Point &p) { diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index 78e1970..acb8194 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -157,11 +157,11 @@ void PerformAttacks::AddNumberAnimations(const TargetSelection &ts) { if (ts.IsBad(i)) { numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite)); numberPosition.push_back( - battle->HeroesPositions()[i]); + battle->HeroAt(i).Position()); } else if (ts.IsGood(i)) { numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite)); numberPosition.push_back( - battle->HeroesPositions()[i]); + battle->HeroAt(i).Position()); } } } @@ -251,10 +251,9 @@ void PerformAttacks::RenderNumbers(SDL_Surface *screen, const Vector &offse void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector &offset) const { 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) { + for (vector >::size_type i(0), end(ts.TargetsHeroes() ? battle->NumHeroes() : battle->MaxMonsters()); i < end; ++i) { if (ts.IsSelected(i)) { - targetAnimation.DrawCenter(screen, positions[i] + offset); + targetAnimation.DrawCenter(screen, (ts.TargetsHeroes() ? battle->HeroAt(i).Position() : battle->MonsterPositions()[i]) + offset); } } }