From: Daniel Karbach Date: Fri, 5 Oct 2012 13:11:59 +0000 (+0200) Subject: extracted tile coordinates calculation X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=b27f427bbb6a1a1ee1230bacb4fce0eb3a8af240;p=l2e.git extracted tile coordinates calculation --- diff --git a/src/map/Map.cpp b/src/map/Map.cpp index 7712a02..10b74d0 100644 --- a/src/map/Map.cpp +++ b/src/map/Map.cpp @@ -30,8 +30,8 @@ Map::Map() const Area &Map::AreaAt(const Vector &offset) const { if (numAreas > 0) { - Vector tileOffset(offset.X() / tileset->Width(), offset.Y() / tileset->Height()); - Vector areaOffset(tileOffset.X() / areas[0].Width(), tileOffset.Y() / areas[0].Height()); + Vector coords(TileCoordinates(offset)); + Vector areaOffset(coords.X() / areas[0].Width(), coords.Y() / areas[0].Height()); int areaIndex(areaOffset.Y() * width + areaOffset.X()); if (areaIndex < numAreas) { return areas[areaIndex]; @@ -48,15 +48,19 @@ const Tile &Map::TileAt(const Vector &offset) const { Trigger *Map::TriggerAt(const geometry::Vector &offset) { // TODO: add support for multiple triggers on a tile? - Vector tilePosition(offset.X() / tileset->Width(), offset.Y() / tileset->Height()); + Vector coords(TileCoordinates(offset)); for (Trigger *i(triggers); i != triggers + numTriggers; ++i) { - if (i->TilePosition() == tilePosition) { + if (i->TilePosition() == coords) { return i; } } return 0; } +Vector Map::TileCoordinates(const Vector &position) const { + return Vector(position.X() / tileset->Width(), position.Y() / tileset->Height()); +} + void Map::Render(SDL_Surface *dest, const Vector &inOffset) const { // TODO: skip invisible areas diff --git a/src/map/Map.h b/src/map/Map.h index dd0185c..bda62bd 100644 --- a/src/map/Map.h +++ b/src/map/Map.h @@ -27,6 +27,7 @@ public: const Area &AreaAt(const geometry::Vector &) const; const Tile &TileAt(const geometry::Vector &) const; Trigger *TriggerAt(const geometry::Vector &); + geometry::Vector TileCoordinates(const geometry::Vector &) const; void Render(SDL_Surface *dest, const geometry::Vector &offset) const;