4 * Created on: Sep 29, 2012
12 #include "../graphics/Sprite.h"
16 using geometry::Vector;
31 const Area &Map::AreaAt(const Vector<int> &offset) const {
33 Vector<int> coords(TileCoordinates(offset));
34 Vector<int> areaOffset(coords / areas[0].Size());
35 int areaIndex(areaOffset.Index(width));
36 if (areaIndex < numAreas) {
37 return areas[areaIndex];
40 throw std::out_of_range("area offset out of bounds");
43 const Tile &Map::TileAt(const Vector<int> &offset) const {
44 const Area &area(AreaAt(offset));
45 Vector<int> tileOffset(TileCoordinates(offset) % area.Size());
46 return area.TileAt(tileOffset);
49 Trigger *Map::TriggerAt(const geometry::Vector<int> &offset) {
50 // TODO: add support for multiple triggers on a tile?
51 Vector<int> coords(TileCoordinates(offset));
52 for (Trigger *i(triggers); i != triggers + numTriggers; ++i) {
53 if (i->TilePosition() == coords) {
60 Vector<int> Map::TileCoordinates(const Vector<int> &position) const {
61 return position / tileset->Size();
65 void Map::Render(SDL_Surface *dest, const Vector<int> &inOffset) const {
66 // TODO: skip invisible areas
67 for (int i(0); i < numAreas; ++i) {
68 const Area &area(areas[i]);
69 Vector<int> offset(inOffset + Vector<int>::FromIndex(i, width) * area.Size() * tileset->Size());
70 area.Render(dest, tileset, offset);