]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/BattleState.cpp
removed debug output from battle state
[l2e.git] / src / battle / BattleState.cpp
index df83c328d2b5a6c32330a1b76cc65444922b2cf0..21de625354487e21694bba6bdf853271c8903405 100644 (file)
@@ -8,13 +8,35 @@
 #include "BattleState.h"
 
 #include "PartyLayout.h"
+#include "../graphics/Sprite.h"
+
+#include <stdexcept>
 
 using app::Application;
+using geometry::Point;
+
+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::Resize(int w, int h) {
+       width = w;
+       height = h;
+}
+
+
 void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
        monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
+       width = screen->w;
+       height = screen->h;
 }
 
 void BattleState::ExitState() {
@@ -31,8 +53,20 @@ void BattleState::UpdateWorld(float deltaT) {
 }
 
 void BattleState::Render(SDL_Surface *screen) {
+       // black for now
+       SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
+       SDL_Rect destRect;
+       destRect.x = (width - background->w) / 2;
+       destRect.y = (height - background->h) / 2;
+       destRect.w = background->w;
+       destRect.h = background->h;
+
        // TODO: center background if screen bigger
-       SDL_BlitSurface(background, 0, screen, 0);
+       SDL_BlitSurface(background, 0, screen, &destRect);
+
+       for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
+               monsters[i].Sprite()->DrawCenterBottom(screen, Point<int>(monsterPositions[i].X() + destRect.x, monsterPositions[i].Y() + destRect.y));
+       }
 }
 
 }