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;
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);
}
}
}
const std::vector<geometry::Point<int> > &MonsterPositions() const { return monsterPositions; }
bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; }
- const std::vector<geometry::Point<int> > &HeroesPositions() const { return heroesPositions; }
bool HeroPositionOccupied(int index) const { return index >= 0 && index < numHeroes; }
void SetRunaway() { ranAway = true; }
MoveMenu moveMenu;
// TODO: combine all data about heros or monsters
std::vector<geometry::Point<int> > monsterPositions;
- std::vector<geometry::Point<int> > heroesPositions;
std::vector<Monster> monsters;
std::vector<Order> attackOrder;
Hero heroes[4];
#include "AttackChoice.h"
#include "Stats.h"
+#include "../geometry/Point.h"
#include "../graphics/Animation.h"
#include "../graphics/Menu.h"
const graphics::Animation *AttackAnimation() const { return attackAnimation; }
const graphics::Animation *SpellAnimation() const { return spellAnimation; }
+ geometry::Point<int> &Position() { return position; }
+ const geometry::Point<int> &Position() const { return position; }
+
graphics::Menu<const common::Spell *> &SpellMenu() { return spellMenu; }
const graphics::Menu<const common::Spell *> &SpellMenu() const { return spellMenu; }
graphics::Menu<const common::Item *> &IkariMenu() { return ikariMenu; }
graphics::AnimationRunner animation;
+ geometry::Point<int> position;
+
graphics::Menu<const common::Spell *> spellMenu;
graphics::Menu<const common::Item *> ikariMenu;
#include "../geometry/Point.h"
+#include <cassert>
#include <vector>
#include <SDL.h>
));
}
}
+ template<class U>
+ geometry::Point<U> CalculatePosition(std::vector<geometry::Point<Uint8> >::size_type index, U width, U height) const {
+ assert(index >= 0 && index < positions.size());
+ return geometry::Point<U>(
+ positions[index].X() * width / 255,
+ positions[index].Y() * height / 223
+ );
+ }
public:
void AddPosition(const geometry::Point<Uint8> &p) {
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());
}
}
}
void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
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) {
+ for (vector<Point<int> >::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);
}
}
}