#include "BattleState.h"
#include "PartyLayout.h"
+#include "../graphics/Sprite.h"
+
+#include <stdexcept>
using app::Application;
+using std::vector;
+
namespace battle {
+void BattleState::AddMonster(const Monster &m) {
+ if (monsters.size() >= monstersLayout->NumPositions()) {
+ throw std::overflow_error("too many monsters for layout");
+ }
+ monsters.push_back(m);
+}
+
+
void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
}
void BattleState::Render(SDL_Surface *screen) {
// TODO: center background if screen bigger
SDL_BlitSurface(background, 0, screen, 0);
+ for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
+ monsters[i].Sprite()->Draw(screen, monsterPositions[i]);
+ }
}
}
#include "app/Application.h"
#include "battle/BattleState.h"
+#include "battle/Monster.h"
#include "battle/PartyLayout.h"
#include "geometry/Point.h"
+#include "graphics/Sprite.h"
#include "sdl/InitScreen.h"
#include "sdl/InitSDL.h"
using app::Application;
using battle::BattleState;
+using battle::Monster;
using battle::PartyLayout;
using geometry::Point;
+using graphics::Sprite;
using sdl::InitScreen;
using sdl::InitSDL;
const int width = 800;
const int height = 480;
- // temporary
+ // temporary test data
SDL_Surface *bg(SDL_CreateRGBSurface(0, width, height, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF));
SDL_FillRect(bg, 0, SDL_MapRGB(bg->format, 0, 0, 0));
PartyLayout monstersLayout;
monstersLayout.AddPosition(Point<Uint8>(100, 50));
monstersLayout.AddPosition(Point<Uint8>(150, 50));
monstersLayout.AddPosition(Point<Uint8>(200, 50));
+ SDL_Surface *white100(SDL_CreateRGBSurface(0, 100, 100, 32, 0xFF000000, 0xFF0000, 0xFF00, 0xFF));
+ SDL_FillRect(white100, 0, SDL_MapRGB(bg->format, 0xFF, 0xFF, 0xFF));
+ Sprite dummyMonsterSprite(white100, 100, 100);
+ Monster monster;
+ monster.SetSprite(&dummyMonsterSprite);
try {
InitSDL sdl;
InitScreen screen(width, height);
- Application app(screen.Screen(), new BattleState(bg, monstersLayout));
+ BattleState *battleState(new BattleState(bg, monstersLayout));
+ battleState->AddMonster(monster);
+ battleState->AddMonster(monster);
+ battleState->AddMonster(monster);
+ battleState->AddMonster(monster);
+ Application app(screen.Screen(), battleState);
app.Run();
return 0;