From 6dd817d079315c392d1a8c2e5d5abcfce1500d30 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 6 Aug 2012 12:26:15 +0200 Subject: [PATCH] better positioning of monsters --- src/battle/BattleState.cpp | 2 +- src/graphics/Sprite.h | 6 ++++++ src/main.cpp | 16 +++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index cc38de2..5f50109 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -47,7 +47,7 @@ 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]); + monsters[i].Sprite()->DrawCenterBottom(screen, monsterPositions[i]); } } diff --git a/src/graphics/Sprite.h b/src/graphics/Sprite.h index c81ed01..475d863 100644 --- a/src/graphics/Sprite.h +++ b/src/graphics/Sprite.h @@ -24,6 +24,12 @@ public: int Width() const { return width; } int Height() const { return height; } void Draw(SDL_Surface *dest, geometry::Point position, int col = 0, int row = 0) const; + void DrawCenterBottom(SDL_Surface *dest, geometry::Point position, int col = 0, int row = 0) const { + geometry::Point translated( + position.X() - (Width() / 2), + position.Y() - Height()); + Draw(dest, translated, col, row); + } private: SDL_Surface *surface; diff --git a/src/main.cpp b/src/main.cpp index b2904b5..71966ee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,12 +37,18 @@ int main(int argc, char **argv) { // 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)); + SDL_FillRect(bg, 0, SDL_MapRGB(bg->format, 0xFF, 0xFF, 0xFF)); + SDL_Rect r; + r.x = 1; + r.y = 1; + r.w = width - 2; + r.h = height - 2; + SDL_FillRect(bg, &r, SDL_MapRGB(bg->format, 0, 0, 0)); PartyLayout monstersLayout; - monstersLayout.AddPosition(Point(50, 50)); - monstersLayout.AddPosition(Point(100, 50)); - monstersLayout.AddPosition(Point(150, 50)); - monstersLayout.AddPosition(Point(200, 50)); + monstersLayout.AddPosition(Point(50, 100)); + monstersLayout.AddPosition(Point(100, 100)); + monstersLayout.AddPosition(Point(150, 100)); + monstersLayout.AddPosition(Point(200, 100)); 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); -- 2.39.2