X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmap%2FArea.cpp;h=985dea2d5462f4aae5ecba7663d6c79651f635d3;hb=0ad5ca97b5df217329bc319d62564a9f46ba11d7;hp=a1ae6804c774b9627fd7b98aeae9b6963fd3b717;hpb=59c4aea0762cbc5f1bf74c5b1b35629408fb92af;p=l2e.git diff --git a/src/map/Area.cpp b/src/map/Area.cpp index a1ae680..985dea2 100644 --- a/src/map/Area.cpp +++ b/src/map/Area.cpp @@ -9,18 +9,42 @@ #include "Tile.h" #include "../graphics/Sprite.h" +#include "../sdl/utility.h" + +#include using geometry::Vector; namespace map { Area::Area() -: tiles(0) +: battlebg(0) +, tiles(0) , numTiles(0) , width(0) { } + +Tile *Area::TileAt(const geometry::Vector &offset) { + int tileIndex(offset.Y() * width + offset.X()); + if (tileIndex < numTiles) { + return tiles +tileIndex; + } else { + return 0; + } +} + +const Tile *Area::TileAt(const geometry::Vector &offset) const { + int tileIndex(offset.Y() * width + offset.X()); + if (tileIndex < numTiles) { + return tiles +tileIndex; + } else { + return 0; + } +} + + 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 +55,35 @@ 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 = Height() * tileset->Height(); + 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( + inOffset.X() + (i % width) * tileset->Width(), + inOffset.Y() + (i / width) * tileset->Height()); + const Tile &tile(tiles[i]); + + if (tile.BlocksNorth()) { + sdl::HorizontalLine(dest, offset, tileset->Width(), color); + } + if (tile.BlocksEast()) { + sdl::VerticalLine(dest, Vector(offset.X() + tileset->Width() - 1, offset.Y()), tileset->Height(), color); + } + if (tile.BlocksSouth()) { + sdl::HorizontalLine(dest, Vector(offset.X(), offset.Y() + tileset->Height() - 1), tileset->Width(), color); + } + if (tile.BlocksWest()) { + sdl::VerticalLine(dest, offset, tileset->Height(), color); + } + } +} + }