4 * Created on: Aug 5, 2012
8 #include "BattleState.h"
10 #include "PartyLayout.h"
11 #include "../graphics/Sprite.h"
16 using app::Application;
17 using geometry::Point;
23 void BattleState::AddMonster(const Monster &m) {
24 if (monsters.size() >= monstersLayout->NumPositions()) {
25 throw std::overflow_error("too many monsters for layout");
27 monsters.push_back(m);
31 void BattleState::Resize(int w, int h) {
37 void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
38 monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
43 void BattleState::ExitState() {
48 void BattleState::HandleEvent(const SDL_Event &) {
52 void BattleState::UpdateWorld(float deltaT) {
56 void BattleState::Render(SDL_Surface *screen) {
58 SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
60 destRect.x = (width - background->w) / 2;
61 destRect.y = (height - background->h) / 2;
62 destRect.w = background->w;
63 destRect.h = background->h;
65 std::cout << "screen: " << screen->w << "x" << screen->h << std::endl;
66 std::cout << "drawing to " << destRect.w << "x" << destRect.h << "+" << destRect.x << "+" << destRect.y << std::endl;
68 // TODO: center background if screen bigger
69 SDL_BlitSurface(background, 0, screen, &destRect);
71 for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
72 monsters[i].Sprite()->DrawCenterBottom(screen, Point<int>(monsterPositions[i].X() + destRect.x, monsterPositions[i].Y() + destRect.y));