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 {
49 destRect.x = inOffset.X();
50 destRect.y = inOffset.Y();
51 destRect.w = Width() * tileset->Width();
53 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF));
54 destRect.y += Height() * tileset->Height() - 1;
55 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF));
56 destRect.y = inOffset.Y();
58 destRect.h = Height() * tileset->Height();
59 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF));
60 destRect.x += Width() * tileset->Width() - 1;
61 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF));
63 for (int i(0); i < numTiles; ++i) {
65 inOffset.X() + (i % width) * tileset->Width(),
66 inOffset.Y() + (i / width) * tileset->Height());
67 const Tile &tile(tiles[i]);
69 if (tile.BlocksNorth()) {
70 destRect.x = offset.X();
71 destRect.y = offset.Y();
72 destRect.w = tileset->Width();
74 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
77 if (tile.BlocksEast()) {
78 destRect.x = offset.X() + tileset->Width() - 1;
79 destRect.y = offset.Y();
81 destRect.h = tileset->Height();
82 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
85 if (tile.BlocksSouth()) {
86 destRect.x = offset.X();
87 destRect.y = offset.Y() + tileset->Height() - 1;
88 destRect.w = tileset->Width();
90 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
93 if (tile.BlocksWest()) {
94 destRect.x = offset.X();
95 destRect.y = offset.Y();
97 destRect.h = tileset->Height();
98 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));