X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmap%2FArea.cpp;h=84dc8a6a527747fce948b6dffb289bc60ee55f0c;hb=3b5b2b79db22ef40c031d791a976310ea49e0d8e;hp=a1ae6804c774b9627fd7b98aeae9b6963fd3b717;hpb=59c4aea0762cbc5f1bf74c5b1b35629408fb92af;p=l2e.git diff --git a/src/map/Area.cpp b/src/map/Area.cpp index a1ae680..84dc8a6 100644 --- a/src/map/Area.cpp +++ b/src/map/Area.cpp @@ -10,6 +10,8 @@ #include "Tile.h" #include "../graphics/Sprite.h" +#include + using geometry::Vector; namespace map { @@ -21,6 +23,17 @@ Area::Area() } + +const Tile &Area::TileAt(const geometry::Vector &offset) const { + int tileIndex(offset.Y() * width + offset.X()); + if (tileIndex < numTiles) { + return tiles[tileIndex]; + } else { + throw std::out_of_range("tile index out of range"); + } +} + + void Area::Render(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector &inOffset) const { for (int i(0); i < numTiles; ++i) { Vector offset( @@ -31,4 +44,60 @@ void Area::Render(SDL_Surface *dest, const graphics::Sprite *tileset, const Vect } } +void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector &inOffset) const { + SDL_Rect destRect; + destRect.x = inOffset.X(); + destRect.y = inOffset.Y(); + destRect.w = Width() * tileset->Width(); + destRect.h = 1; + SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF)); + destRect.y += Height() * tileset->Height() - 1; + SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF)); + destRect.y = inOffset.Y(); + destRect.w = 1; + destRect.h = Height() * tileset->Height(); + SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF)); + destRect.x += Width() * tileset->Width() - 1; + SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF)); + + for (int i(0); i < numTiles; ++i) { + Vector offset( + inOffset.X() + (i % width) * tileset->Width(), + inOffset.Y() + (i / width) * tileset->Height()); + const Tile &tile(tiles[i]); + + if (tile.BlocksNorth()) { + 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()) { + 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()) { + 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()) { + 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)); + } + } +} + }