4 * Created on: Sep 26, 2012
11 #include "../graphics/Sprite.h"
15 using geometry::Vector;
27 const Tile &Area::TileAt(const geometry::Vector<int> &offset) const {
28 int tileIndex(offset.Y() * width + offset.X());
29 if (tileIndex < numTiles) {
30 return tiles[tileIndex];
32 throw std::out_of_range("tile index out of range");
37 void Area::Render(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector<int> &inOffset) const {
38 for (int i(0); i < numTiles; ++i) {
40 inOffset.X() + (i % width) * tileset->Width(),
41 inOffset.Y() + (i / width) * tileset->Height());
42 const Tile &tile(tiles[i]);
43 tileset->Draw(dest, offset, tile.Offset().X(), tile.Offset().Y());
47 void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector<int> &inOffset) const {
48 for (int i(0); i < numTiles; ++i) {
50 inOffset.X() + (i % width) * tileset->Width(),
51 inOffset.Y() + (i / width) * tileset->Height());
52 const Tile &tile(tiles[i]);
54 if (tile.BlocksNorth()) {
56 destRect.x = offset.X();
57 destRect.y = offset.Y();
58 destRect.w = tileset->Width();
60 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
63 if (tile.BlocksEast()) {
65 destRect.x = offset.X() + tileset->Width() - 1;
66 destRect.y = offset.Y();
68 destRect.h = tileset->Height();
69 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
72 if (tile.BlocksSouth()) {
74 destRect.x = offset.X();
75 destRect.y = offset.Y() + tileset->Height() - 1;
76 destRect.w = tileset->Width();
78 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
81 if (tile.BlocksWest()) {
83 destRect.x = offset.X();
84 destRect.y = offset.Y();
86 destRect.h = tileset->Height();
87 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));