From: Daniel Karbach Date: Mon, 6 Aug 2012 10:12:09 +0000 (+0200) Subject: added monster drawing routine in battle state X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=509ef53f0adeb204167aabe1715f3a230f8c59fe;p=l2e.git added monster drawing routine in battle state also added some dummy monsters in main to test it --- diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index df83c32..cc38de2 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -8,11 +8,24 @@ #include "BattleState.h" #include "PartyLayout.h" +#include "../graphics/Sprite.h" + +#include 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::size_type i(0), end(monsters.size()); i < end; ++i) { + monsters[i].Sprite()->Draw(screen, monsterPositions[i]); + } } } diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 05bd7c9..ccc2425 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -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(); diff --git a/src/battle/Monster.h b/src/battle/Monster.h index 0b35d31..e77a14b 100644 --- a/src/battle/Monster.h +++ b/src/battle/Monster.h @@ -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; diff --git a/src/main.cpp b/src/main.cpp index 4e5fb47..b2904b5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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" @@ -17,8 +19,10 @@ 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(100, 50)); monstersLayout.AddPosition(Point(150, 50)); monstersLayout.AddPosition(Point(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;