4 * Created on: Sep 29, 2012
12 #include "../graphics/Sprite.h"
16 using geometry::Vector;
33 const Area *Map::AreaAt(const Vector<int> &offset) const {
35 Vector<int> coords(TileCoordinates(offset));
36 Vector<int> areaOffset(coords / areas[0].Size());
37 int areaIndex(areaOffset.Index(width));
38 if (areaIndex < numAreas) {
39 return areas + areaIndex;
45 const Tile *Map::TileAt(const Vector<int> &offset) const {
46 const Area *area(AreaAt(offset));
48 Vector<int> tileOffset(TileCoordinates(offset) % area->Size());
49 return area->TileAt(tileOffset);
55 Trigger *Map::TriggerAt(const geometry::Vector<int> &offset) {
56 // TODO: add support for multiple triggers on a tile?
57 Vector<int> coords(TileCoordinates(offset));
58 for (Trigger *i(triggers); i != triggers + numTriggers; ++i) {
59 if (i->TilePosition() == coords) {
66 Vector<int> Map::TileCoordinates(const Vector<int> &position) const {
67 return position / tileset->Size();
71 void Map::Render(SDL_Surface *dest, const Vector<int> &inOffset) const {
72 // TODO: skip invisible areas
73 for (int i(0); i < numAreas; ++i) {
74 const Area &area(areas[i]);
75 Vector<int> offset(inOffset + Vector<int>::FromIndex(i, width) * area.Size() * tileset->Size());
76 area.Render(dest, tileset, offset);
80 void Map::RenderDebug(SDL_Surface *dest, const Vector<int> &inOffset) const {
81 // TODO: skip invisible areas
82 for (int i(0); i < numAreas; ++i) {
83 const Area &area(areas[i]);
84 Vector<int> offset(inOffset + Vector<int>::FromIndex(i, width) * area.Size() * tileset->Size());
85 area.RenderDebug(dest, tileset, offset);
87 for (int i(0); i < numTriggers; ++i) {
88 Vector<int> offset((triggers[i].TilePosition() * tileset->Size()) + inOffset);
90 destRect.x = offset.X() + (tileset->Width() / 4);
91 destRect.y = offset.Y() + (tileset->Height() / 4);
92 destRect.w = tileset->Width() / 2;
93 destRect.h = tileset->Height() / 2;
94 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0xFF, 0xFF));