X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmap%2FMap.cpp;h=1c55eaf0690a552d470efcbb97a4be5ffe2ca2dd;hb=6e88a625710c7936f87b38ecf6094472f3a49f4f;hp=fc664c1d7d4e26c0060176bf0283002abfbbe5a6;hpb=ed792d6d00d822384d79d049e644e372f7c3b4cd;p=l2e.git diff --git a/src/map/Map.cpp b/src/map/Map.cpp index fc664c1..1c55eaf 100644 --- a/src/map/Map.cpp +++ b/src/map/Map.cpp @@ -8,8 +8,10 @@ #include "Map.h" #include "Area.h" +#include "Tile.h" #include "Trigger.h" #include "../graphics/Sprite.h" +#include "../sdl/utility.h" #include @@ -19,6 +21,7 @@ namespace map { Map::Map() : tileset(0) +, battlebg(0) , areas(0) , numAreas(0) , triggers(0) @@ -30,6 +33,18 @@ Map::Map() } +Area *Map::AreaAt(const Vector &offset) { + if (numAreas > 0) { + Vector coords(TileCoordinates(offset)); + Vector areaOffset(coords / areas[0].Size()); + int areaIndex(areaOffset.Index(width)); + if (areaIndex < numAreas) { + return areas + areaIndex; + } + } + return 0; +} + const Area *Map::AreaAt(const Vector &offset) const { if (numAreas > 0) { Vector coords(TileCoordinates(offset)); @@ -42,6 +57,16 @@ const Area *Map::AreaAt(const Vector &offset) const { return 0; } +Tile *Map::TileAt(const Vector &offset) { + Area *area(AreaAt(offset)); + if (area) { + Vector tileOffset(TileCoordinates(offset) % area->Size()); + return area->TileAt(tileOffset); + } else { + return 0; + } +} + const Tile *Map::TileAt(const Vector &offset) const { const Area *area(AreaAt(offset)); if (area) { @@ -63,6 +88,18 @@ Trigger *Map::TriggerAt(const geometry::Vector &offset) { return 0; } +SDL_Surface *Map::BattleBackgroundAt(const geometry::Vector &position) { + Tile *tile(TileAt(position)); + if (tile && tile->BattleBackground()) { + return tile->BattleBackground(); + } + Area *area(AreaAt(position)); + if (area && area->BattleBackground()) { + return area->BattleBackground(); + } + return battlebg; +} + Vector Map::TileCoordinates(const Vector &position) const { return position / tileset->Size(); } @@ -86,12 +123,29 @@ void Map::RenderDebug(SDL_Surface *dest, const Vector &inOffset) const { } for (int i(0); i < numTriggers; ++i) { Vector offset((triggers[i].TilePosition() * tileset->Size()) + inOffset); - SDL_Rect destRect; - destRect.x = offset.X() + (tileset->Width() / 4); - destRect.y = offset.Y() + (tileset->Height() / 4); - destRect.w = tileset->Width() / 2; - destRect.h = tileset->Height() / 2; - SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0xFF, 0xFF)); + switch (triggers[i].GetType()) { + case Trigger::TYPE_NORTH: + sdl::HorizontalLine(dest, offset + (tileset->Size() / 4), tileset->Width() / 2, SDL_MapRGB(dest->format, 0x00, 0xFF, 0xFF)); + break; + case Trigger::TYPE_EAST: + sdl::VerticalLine(dest, offset + Vector(tileset->Width() * 3 / 4, tileset->Height() / 4), tileset->Height() / 2, SDL_MapRGB(dest->format, 0x00, 0xFF, 0xFF)); + break; + case Trigger::TYPE_SOUTH: + sdl::HorizontalLine(dest, offset + Vector(tileset->Width() / 4, tileset->Height() * 3 / 4), tileset->Width() / 2, SDL_MapRGB(dest->format, 0x00, 0xFF, 0xFF)); + break; + case Trigger::TYPE_WEST: + sdl::VerticalLine(dest, offset + (tileset->Size() / 4), tileset->Width() / 2, SDL_MapRGB(dest->format, 0x00, 0xFF, 0xFF)); + break; + case Trigger::TYPE_CONTACT: { + SDL_Rect destRect; + destRect.x = offset.X() + (tileset->Width() / 4); + destRect.y = offset.Y() + (tileset->Height() / 4); + destRect.w = tileset->Width() / 2; + destRect.h = tileset->Height() / 2; + SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0xFF, 0xFF)); + } + break; + } } }