X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmap%2FMap.cpp;h=1c55eaf0690a552d470efcbb97a4be5ffe2ca2dd;hb=77915e0186f4fc0788054eb34651c726b80d981c;hp=d7c0b32e49c77c6fa1aa08927a7cbe74ff317243;hpb=7fb774ec1df3d550cd8a6805bdc69c11ad36e498;p=l2e.git diff --git a/src/map/Map.cpp b/src/map/Map.cpp index d7c0b32..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,22 +33,48 @@ Map::Map() } -const Area &Map::AreaAt(const Vector &offset) const { +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 areas + areaIndex; } } - throw std::out_of_range("area offset out of bounds"); + return 0; +} + +const Area *Map::AreaAt(const Vector &offset) const { + 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 Tile &Map::TileAt(const Vector &offset) const { - const Area &area(AreaAt(offset)); - Vector tileOffset(TileCoordinates(offset) % area.Size()); - return area.TileAt(tileOffset); +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) { + Vector tileOffset(TileCoordinates(offset) % area->Size()); + return area->TileAt(tileOffset); + } else { + return 0; + } } Trigger *Map::TriggerAt(const geometry::Vector &offset) { @@ -59,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(); } @@ -82,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; + } } }