X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmap%2FArea.cpp;h=9c066d646f021a0b8d0d644bb6806fbb5f98622d;hb=d2d8ff1fd5f55e8b43d48ae5e75c216492e2f032;hp=84dc8a6a527747fce948b6dffb289bc60ee55f0c;hpb=9474df57053c3d151e47d037c26af8229341117a;p=l2e.git diff --git a/src/map/Area.cpp b/src/map/Area.cpp index 84dc8a6..9c066d6 100644 --- a/src/map/Area.cpp +++ b/src/map/Area.cpp @@ -9,6 +9,7 @@ #include "Tile.h" #include "../graphics/Sprite.h" +#include "../sdl/utility.h" #include @@ -24,12 +25,12 @@ Area::Area() } -const Tile &Area::TileAt(const geometry::Vector &offset) const { +const Tile *Area::TileAt(const geometry::Vector &offset) const { int tileIndex(offset.Y() * width + offset.X()); if (tileIndex < numTiles) { - return tiles[tileIndex]; + return tiles +tileIndex; } else { - throw std::out_of_range("tile index out of range"); + return 0; } } @@ -49,16 +50,10 @@ void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const 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)); + sdl::OutlineRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF)); + + Uint32 color(SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00)); for (int i(0); i < numTiles; ++i) { Vector offset( @@ -67,35 +62,16 @@ void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const 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)); + sdl::HorizontalLine(dest, offset, tileset->Width(), color); } - 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)); + sdl::VerticalLine(dest, Vector(offset.X() + tileset->Width() - 1, offset.Y()), tileset->Height(), color); } - 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)); + sdl::HorizontalLine(dest, Vector(offset.X(), offset.Y() + tileset->Height() - 1), tileset->Width(), color); } - 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)); + sdl::VerticalLine(dest, offset, tileset->Height(), color); } } }