4 * Created on: Aug 5, 2012
8 #include "BattleState.h"
10 #include "PartyLayout.h"
11 #include "../graphics/Sprite.h"
15 using app::Application;
16 using geometry::Point;
22 void BattleState::AddMonster(const Monster &m) {
23 if (monsters.size() >= monstersLayout->NumPositions()) {
24 throw std::overflow_error("too many monsters for layout");
26 monsters.push_back(m);
29 void BattleState::AddHero(const Hero &h) {
30 if (heroes.size() >= heroesLayout->NumPositions()) {
31 throw std::overflow_error("too many heroes for layout");
37 void BattleState::Resize(int w, int h) {
42 void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
43 monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
44 heroesLayout->CalculatePositions(background->w, background->h, heroesPositions);
47 void BattleState::ExitState() {
52 void BattleState::HandleEvent(const SDL_Event &) {
56 void BattleState::UpdateWorld(float deltaT) {
60 void BattleState::Render(SDL_Surface *screen) {
62 SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
64 destRect.x = (screen->w - background->w) / 2;
65 destRect.y = (screen->h - background->h) / 2;
66 destRect.w = background->w;
67 destRect.h = background->h;
69 // TODO: center background if screen bigger
70 SDL_BlitSurface(background, 0, screen, &destRect);
72 for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
73 monsters[i].Sprite()->DrawCenterBottom(screen, Point<int>(monsterPositions[i].X() + destRect.x, monsterPositions[i].Y() + destRect.y));
76 for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
77 heroes[i].Sprite()->DrawCenterBottom(screen, Point<int>(heroesPositions[i].X() + destRect.x, heroesPositions[i].Y() + destRect.y));