]> git.localhorst.tv Git - l2e.git/commitdiff
better positioning of monsters
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 6 Aug 2012 10:26:15 +0000 (12:26 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 6 Aug 2012 10:26:15 +0000 (12:26 +0200)
src/battle/BattleState.cpp
src/graphics/Sprite.h
src/main.cpp

index cc38de237da120164584ec9ce2026267bac468cc..5f50109b7585682c520d8ff09921de6787a80f20 100644 (file)
@@ -47,7 +47,7 @@ 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]);
+               monsters[i].Sprite()->DrawCenterBottom(screen, monsterPositions[i]);
        }
 }
 
index c81ed01984c7e1d00bd9866212808df4be34ffaa..475d863638d060e3a2bad0d1ff4a1575d7fb2fb4 100644 (file)
@@ -24,6 +24,12 @@ public:
        int Width() const { return width; }
        int Height() const { return height; }
        void Draw(SDL_Surface *dest, geometry::Point<int> position, int col = 0, int row = 0) const;
+       void DrawCenterBottom(SDL_Surface *dest, geometry::Point<int> position, int col = 0, int row = 0) const {
+               geometry::Point<int> translated(
+                               position.X() - (Width() / 2),
+                               position.Y() - Height());
+               Draw(dest, translated, col, row);
+       }
 
 private:
        SDL_Surface *surface;
index b2904b5c6c3edfee8467e3242b1515d3d65ee74d..71966eed653cf39bfcfbfacc93c8843874de8f5d 100644 (file)
@@ -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<Uint8>(50, 50));
-       monstersLayout.AddPosition(Point<Uint8>(100, 50));
-       monstersLayout.AddPosition(Point<Uint8>(150, 50));
-       monstersLayout.AddPosition(Point<Uint8>(200, 50));
+       monstersLayout.AddPosition(Point<Uint8>(50, 100));
+       monstersLayout.AddPosition(Point<Uint8>(100, 100));
+       monstersLayout.AddPosition(Point<Uint8>(150, 100));
+       monstersLayout.AddPosition(Point<Uint8>(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);