4 * Created on: Sep 29, 2012
11 #include "../graphics/Sprite.h"
15 using geometry::Vector;
28 const Area &Map::AreaAt(const Vector<int> &offset) const {
30 Vector<int> tileOffset(offset.X() / tileset->Width(), offset.Y() / tileset->Height());
31 Vector<int> areaOffset(tileOffset.X() / areas[0].Width(), tileOffset.Y() / areas[0].Height());
32 int areaIndex(areaOffset.Y() * width + areaOffset.X());
33 if (areaIndex < numAreas) {
34 return areas[areaIndex];
37 throw std::out_of_range("area offset out of bounds");
40 const Tile &Map::TileAt(const Vector<int> &offset) const {
41 const Area &area(AreaAt(offset));
42 Vector<int> tileOffset((offset.X() / tileset->Width()) % area.Width(), (offset.Y() / tileset->Height()) % area.Height());
43 return area.TileAt(tileOffset);
47 void Map::Render(SDL_Surface *dest, const Vector<int> &inOffset) const {
48 // TODO: skip invisible areas
49 for (int i(0); i < numAreas; ++i) {
50 const Area &area(areas[i]);
52 inOffset.X() + (i % width) * area.Width() * tileset->Width(),
53 inOffset.Y() + (i / width) * area.Height() * tileset->Height());
54 area.Render(dest, tileset, offset);