X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmap%2FMap.cpp;h=fc664c1d7d4e26c0060176bf0283002abfbbe5a6;hb=d2d8ff1fd5f55e8b43d48ae5e75c216492e2f032;hp=10b74d079a01d43b422fa7719bb1a84298aa8d8d;hpb=b27f427bbb6a1a1ee1230bacb4fce0eb3a8af240;p=l2e.git diff --git a/src/map/Map.cpp b/src/map/Map.cpp index 10b74d0..fc664c1 100644 --- a/src/map/Map.cpp +++ b/src/map/Map.cpp @@ -23,27 +23,33 @@ Map::Map() , numAreas(0) , triggers(0) , numTriggers(0) +, entities(0) +, numEntities(0) , width(0) { } -const Area &Map::AreaAt(const Vector &offset) const { +const Area *Map::AreaAt(const Vector &offset) const { if (numAreas > 0) { Vector coords(TileCoordinates(offset)); - Vector areaOffset(coords.X() / areas[0].Width(), coords.Y() / areas[0].Height()); - int areaIndex(areaOffset.Y() * width + areaOffset.X()); + 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 Tile &Map::TileAt(const Vector &offset) const { - const Area &area(AreaAt(offset)); - Vector tileOffset((offset.X() / tileset->Width()) % area.Width(), (offset.Y() / tileset->Height()) % area.Height()); - return area.TileAt(tileOffset); +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) { @@ -58,7 +64,7 @@ Trigger *Map::TriggerAt(const geometry::Vector &offset) { } Vector Map::TileCoordinates(const Vector &position) const { - return Vector(position.X() / tileset->Width(), position.Y() / tileset->Height()); + return position / tileset->Size(); } @@ -66,11 +72,27 @@ void Map::Render(SDL_Surface *dest, const Vector &inOffset) const { // TODO: skip invisible areas for (int i(0); i < numAreas; ++i) { const Area &area(areas[i]); - Vector offset( - inOffset.X() + (i % width) * area.Width() * tileset->Width(), - inOffset.Y() + (i / width) * area.Height() * tileset->Height()); + Vector offset(inOffset + Vector::FromIndex(i, width) * area.Size() * tileset->Size()); area.Render(dest, tileset, offset); } } +void Map::RenderDebug(SDL_Surface *dest, const Vector &inOffset) const { + // TODO: skip invisible areas + for (int i(0); i < numAreas; ++i) { + const Area &area(areas[i]); + Vector offset(inOffset + Vector::FromIndex(i, width) * area.Size() * tileset->Size()); + area.RenderDebug(dest, tileset, offset); + } + 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)); + } +} + }