const Area &Map::AreaAt(const Vector<int> &offset) const {
if (numAreas > 0) {
- Vector<int> tileOffset(offset.X() / tileset->Width(), offset.Y() / tileset->Height());
- Vector<int> areaOffset(tileOffset.X() / areas[0].Width(), tileOffset.Y() / areas[0].Height());
+ Vector<int> coords(TileCoordinates(offset));
+ Vector<int> areaOffset(coords.X() / areas[0].Width(), coords.Y() / areas[0].Height());
int areaIndex(areaOffset.Y() * width + areaOffset.X());
if (areaIndex < numAreas) {
return areas[areaIndex];
Trigger *Map::TriggerAt(const geometry::Vector<int> &offset) {
// TODO: add support for multiple triggers on a tile?
- Vector<int> tilePosition(offset.X() / tileset->Width(), offset.Y() / tileset->Height());
+ Vector<int> coords(TileCoordinates(offset));
for (Trigger *i(triggers); i != triggers + numTriggers; ++i) {
- if (i->TilePosition() == tilePosition) {
+ if (i->TilePosition() == coords) {
return i;
}
}
return 0;
}
+Vector<int> Map::TileCoordinates(const Vector<int> &position) const {
+ return Vector<int>(position.X() / tileset->Width(), position.Y() / tileset->Height());
+}
+
void Map::Render(SDL_Surface *dest, const Vector<int> &inOffset) const {
// TODO: skip invisible areas
const Area &AreaAt(const geometry::Vector<int> &) const;
const Tile &TileAt(const geometry::Vector<int> &) const;
Trigger *TriggerAt(const geometry::Vector<int> &);
+ geometry::Vector<int> TileCoordinates(const geometry::Vector<int> &) const;
void Render(SDL_Surface *dest, const geometry::Vector<int> &offset) const;