4 * Created on: Aug 5, 2012
8 #ifndef BATTLE_BATTLESTATE_H_
9 #define BATTLE_BATTLESTATE_H_
11 #include "AttackChoice.h"
12 #include "AttackTypeMenu.h"
17 #include "Resources.h"
18 #include "../app/State.h"
19 #include "../geometry/Point.h"
20 #include "../geometry/Vector.h"
25 namespace app { class Input; }
41 BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const Resources *res)
42 : background(background)
43 , monstersLayout(&monstersLayout)
44 , heroesLayout(&heroesLayout)
46 , attackTypeMenu(res->attackIcons)
47 , moveMenu(res->moveIcons)
51 void AddMonster(const Monster &);
52 void AddHero(const Hero &);
55 virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
56 virtual void ExitState(app::Application &ctrl, SDL_Surface *screen);
57 virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen);
58 virtual void PauseState(app::Application &ctrl, SDL_Surface *screen);
60 virtual void Resize(int width, int height);
62 virtual void HandleInput(const app::Input &);
63 virtual void UpdateWorld(float deltaT);
64 virtual void Render(SDL_Surface *);
67 const Resources &Res() const { return *res; }
68 AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
69 MoveMenu &GetMoveMenu() { return moveMenu; }
71 bool HasMoreHeroes() const { return activeHero < (int) heroes.size(); }
72 void NextHero() { ++activeHero; }
73 bool BeforeFirstHero() const { return activeHero < 0; }
74 void PreviousHero() { --activeHero; }
75 Hero &ActiveHero() { return heroes[activeHero]; }
76 const Hero &ActiveHero() const { return heroes[activeHero]; }
77 bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; }
78 void SetAttackType(AttackChoice::Type t) { attackChoices[activeHero].SetType(t); }
79 bool AttackSelectionDone() const { return activeHero >= (int) heroes.size(); }
82 geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
83 return geometry::Vector<int>(
84 (screen->w - background->w) / 2,
85 (screen->h - background->h) / 2);
87 int BackgroundWidth() const { return background->w; }
88 int BackgroundHeight() const { return background->h; }
90 void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
91 void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
92 void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
93 void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
96 SDL_Surface *background;
97 const PartyLayout *monstersLayout;
98 const PartyLayout *heroesLayout;
100 AttackTypeMenu attackTypeMenu;
102 std::vector<geometry::Point<int> > monsterPositions;
103 std::vector<geometry::Point<int> > heroesPositions;
104 std::vector<Monster> monsters;
105 std::vector<Hero> heroes;
106 std::vector<HeroTag> heroTags;
107 std::vector<AttackChoice> attackChoices;
114 #endif /* BATTLE_BATTLESTATE_H_ */