]> git.localhorst.tv Git - l2e.git/commitdiff
added monster drawing routine in battle state
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 6 Aug 2012 10:12:09 +0000 (12:12 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 6 Aug 2012 10:12:09 +0000 (12:12 +0200)
also added some dummy monsters in main to test it

src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Monster.h
src/main.cpp

index df83c328d2b5a6c32330a1b76cc65444922b2cf0..cc38de237da120164584ec9ce2026267bac468cc 100644 (file)
@@ -8,11 +8,24 @@
 #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);
 }
@@ -33,6 +46,9 @@ void BattleState::UpdateWorld(float deltaT) {
 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]);
+       }
 }
 
 }
index 05bd7c95128ae6352b9360d3b1cc34243aab89a4..ccc242512bf87ddbecf25e0656f86d7cb0e1a8fa 100644 (file)
@@ -27,6 +27,9 @@ public:
        : background(background)
        , monstersLayout(&monstersLayout) { }
 
+public:
+       void AddMonster(const Monster &);
+
 public:
        virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
        virtual void ExitState();
index 0b35d31b742d43ca17bc8b906717806ccea2eecd..e77a14b9e326a1e4eae1ec1fb980bafcbe271a0e 100644 (file)
@@ -49,6 +49,10 @@ public:
        const /* Script */ void *AttackScript() { return attackScript; }
        const /* Script */ void *DefenseScript() { return defenseScript; }
 
+// temporary setters until loader is implemented
+public:
+       void SetSprite(graphics::Sprite *s) { sprite = s; }
+
 private:
        const char *name;
        graphics::Sprite *sprite;
index 4e5fb471543cf5378bfddd98c77c9e14533e3a92..b2904b5c6c3edfee8467e3242b1515d3d65ee74d 100644 (file)
@@ -7,8 +7,10 @@
 
 #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;
 
@@ -31,7 +35,7 @@ int main(int argc, char **argv) {
        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;
@@ -39,12 +43,22 @@ int main(int argc, char **argv) {
        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;