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);
30 void BattleState::Resize(int w, int h) {
36 void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
37 monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
42 void BattleState::ExitState() {
47 void BattleState::HandleEvent(const SDL_Event &) {
51 void BattleState::UpdateWorld(float deltaT) {
55 void BattleState::Render(SDL_Surface *screen) {
57 SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
59 destRect.x = (width - background->w) / 2;
60 destRect.y = (height - background->h) / 2;
61 destRect.w = background->w;
62 destRect.h = background->h;
64 // TODO: center background if screen bigger
65 SDL_BlitSurface(background, 0, screen, &destRect);
67 for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
68 monsters[i].Sprite()->DrawCenterBottom(screen, Point<int>(monsterPositions[i].X() + destRect.x, monsterPositions[i].Y() + destRect.y));