From e1b949217f6cf25cb080e514a5f6a40935f0c8fa Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 6 Aug 2012 13:18:00 +0200 Subject: [PATCH] added heroes' party layout to battle state --- src/battle/BattleState.cpp | 10 ++++------ src/battle/BattleState.h | 9 ++++----- src/main.cpp | 7 ++++++- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index 21de625..d1a983f 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -28,15 +28,13 @@ void BattleState::AddMonster(const Monster &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; + heroesLayout->CalculatePositions(background->w, background->h, heroesPositions); } void BattleState::ExitState() { @@ -56,8 +54,8 @@ 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.x = (screen->w - background->w) / 2; + destRect.y = (screen->h - background->h) / 2; destRect.w = background->w; destRect.h = background->h; diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 52238eb..06b8fbd 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -23,11 +23,10 @@ class BattleState : public app::State { public: - BattleState(SDL_Surface *background, const PartyLayout &monstersLayout) + BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout) : background(background) , monstersLayout(&monstersLayout) - , width(0) - , height(0) { } + , heroesLayout(&heroesLayout) { } public: void AddMonster(const Monster &); @@ -45,10 +44,10 @@ public: private: SDL_Surface *background; const PartyLayout *monstersLayout; + const PartyLayout *heroesLayout; std::vector > monsterPositions; + std::vector > heroesPositions; std::vector monsters; - int width; - int height; }; diff --git a/src/main.cpp b/src/main.cpp index 8f92a35..2ecdbb6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,6 +49,11 @@ int main(int argc, char **argv) { monstersLayout.AddPosition(Point(100, 100)); monstersLayout.AddPosition(Point(150, 100)); monstersLayout.AddPosition(Point(200, 100)); + PartyLayout heroesLayout; + heroesLayout.AddPosition(Point(45, 132)); + heroesLayout.AddPosition(Point(174, 136)); + heroesLayout.AddPosition(Point(110, 143)); + heroesLayout.AddPosition(Point(239, 148)); 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); @@ -59,7 +64,7 @@ int main(int argc, char **argv) { InitSDL sdl; InitScreen screen(width, height); - BattleState *battleState(new BattleState(bg, monstersLayout)); + BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout)); battleState->AddMonster(monster); battleState->AddMonster(monster); battleState->AddMonster(monster); -- 2.39.2