]> git.localhorst.tv Git - l2e.git/commitdiff
added debug mode for maps
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 6 Oct 2012 20:08:11 +0000 (22:08 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 6 Oct 2012 20:08:11 +0000 (22:08 +0200)
currently shows tile blocking flags as little red lines

src/map/Area.cpp
src/map/Area.h
src/map/Map.cpp
src/map/Map.h
src/map/MapState.cpp
src/map/MapState.h

index 292b8952f21ecca579aa4af9a18112e968e5810a..0b25a04bd7b512e9ca1f913856ff410f602b5667 100644 (file)
@@ -44,4 +44,49 @@ void Area::Render(SDL_Surface *dest, const graphics::Sprite *tileset, const Vect
        }
 }
 
+void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector<int> &inOffset) const {
+       for (int i(0); i < numTiles; ++i) {
+               Vector<int> offset(
+                               inOffset.X() + (i % width) * tileset->Width(),
+                               inOffset.Y() + (i / width) * tileset->Height());
+               const Tile &tile(tiles[i]);
+
+               if (tile.BlocksNorth()) {
+                       SDL_Rect destRect;
+                       destRect.x = offset.X();
+                       destRect.y = offset.Y();
+                       destRect.w = tileset->Width();
+                       destRect.h = 1;
+                       SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
+               }
+
+               if (tile.BlocksEast()) {
+                       SDL_Rect destRect;
+                       destRect.x = offset.X() + tileset->Width() - 1;
+                       destRect.y = offset.Y();
+                       destRect.w = 1;
+                       destRect.h = tileset->Height();
+                       SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
+               }
+
+               if (tile.BlocksSouth()) {
+                       SDL_Rect destRect;
+                       destRect.x = offset.X();
+                       destRect.y = offset.Y() + tileset->Height() - 1;
+                       destRect.w = tileset->Width();
+                       destRect.h = 1;
+                       SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
+               }
+
+               if (tile.BlocksWest()) {
+                       SDL_Rect destRect;
+                       destRect.x = offset.X();
+                       destRect.y = offset.Y();
+                       destRect.w = 1;
+                       destRect.h = tileset->Height();
+                       SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
+               }
+       }
+}
+
 }
index e2b6a1ede7a0a0dcbde2c8502bfd8df3b4180a41..0a563390c6221053ef3b2274360b08e197b6880a 100644 (file)
@@ -29,6 +29,7 @@ public:
        const Tile &TileAt(const geometry::Vector<int> &) const;
 
        void Render(SDL_Surface *dest, const graphics::Sprite *tileset, const geometry::Vector<int> &offset) const;
+       void RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const geometry::Vector<int> &offset) const;
 
 // temporary setters
 public:
index 20f2fa575585eebd8cc0fe070d4fafb50f2b1a00..c7d75f18af409dc3774fadfa8098d6a1b3bf8851 100644 (file)
@@ -71,4 +71,13 @@ void Map::Render(SDL_Surface *dest, const Vector<int> &inOffset) const {
        }
 }
 
+void Map::RenderDebug(SDL_Surface *dest, const Vector<int> &inOffset) const {
+       // TODO: skip invisible areas
+       for (int i(0); i < numAreas; ++i) {
+               const Area &area(areas[i]);
+               Vector<int> offset(inOffset + Vector<int>::FromIndex(i, width) * area.Size() * tileset->Size());
+               area.RenderDebug(dest, tileset, offset);
+       }
+}
+
 }
index bda62bdd83c5485fa5e1aedddd00a98745d33272..a1b9cebd593c5dd9f809f8fb1d1edb061b9b0b56 100644 (file)
@@ -30,6 +30,7 @@ public:
        geometry::Vector<int> TileCoordinates(const geometry::Vector<int> &) const;
 
        void Render(SDL_Surface *dest, const geometry::Vector<int> &offset) const;
+       void RenderDebug(SDL_Surface *dest, const geometry::Vector<int> &offset) const;
 
 // temporary setters
 public:
index 108d97c123c7d4e9f60b81170fcd3019ff0002f9..350a1f48f8be2813585fef2fbc8233b5f4f06000 100644 (file)
@@ -27,7 +27,8 @@ MapState::MapState(Map *map)
 , camera(100, 100, &tempTarget)
 , walkingSpeed(64)
 , nextDirection(-1)
-, afterLock(false) {
+, afterLock(false)
+, debug(false) {
 
 }
 
@@ -67,6 +68,10 @@ void MapState::HandleEvents(const Input &input) {
        } else {
                nextDirection = -1;
        }
+
+       if (input.JustPressed(Input::DEBUG_1)) {
+               debug = !debug;
+       }
 }
 
 void MapState::UpdateWorld(float deltaT) {
@@ -278,6 +283,10 @@ void MapState::Render(SDL_Surface *screen) {
        Vector<int> offset(camera.CalculateOffset());
        map->Render(screen, offset);
 
+       if (debug) {
+               map->RenderDebug(screen, offset);
+       }
+
        std::sort(entities.begin(), entities.end(), ZCompare);
        for (std::vector<Entity *>::iterator i(entities.begin()), end(entities.end()); i != end; ++i) {
                (*i)->Render(screen, offset);
index e7a75b6fca784f5dfb04c9a2b64154938a36dfbf..4ba149db1d96c3e05749c4a5b32f411b5938dfc5 100644 (file)
@@ -69,6 +69,7 @@ private:
        float walkingSpeed;
        int nextDirection;
        bool afterLock;
+       bool debug;
 
 };