4 * Created on: Sep 26, 2012
11 #include "../graphics/Sprite.h"
12 #include "../sdl/utility.h"
16 using geometry::Vector;
28 const Tile &Area::TileAt(const geometry::Vector<int> &offset) const {
29 int tileIndex(offset.Y() * width + offset.X());
30 if (tileIndex < numTiles) {
31 return tiles[tileIndex];
33 throw std::out_of_range("tile index out of range");
38 void Area::Render(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector<int> &inOffset) const {
39 for (int i(0); i < numTiles; ++i) {
41 inOffset.X() + (i % width) * tileset->Width(),
42 inOffset.Y() + (i / width) * tileset->Height());
43 const Tile &tile(tiles[i]);
44 tileset->Draw(dest, offset, tile.Offset().X(), tile.Offset().Y());
48 void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector<int> &inOffset) const {
50 destRect.x = inOffset.X();
51 destRect.y = inOffset.Y();
52 destRect.w = Width() * tileset->Width();
53 destRect.h = Height() * tileset->Height();
54 sdl::OutlineRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF));
56 Uint32 color(SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
58 for (int i(0); i < numTiles; ++i) {
60 inOffset.X() + (i % width) * tileset->Width(),
61 inOffset.Y() + (i / width) * tileset->Height());
62 const Tile &tile(tiles[i]);
64 if (tile.BlocksNorth()) {
65 sdl::HorizontalLine(dest, offset, tileset->Width(), color);
67 if (tile.BlocksEast()) {
68 sdl::VerticalLine(dest, Vector<int>(offset.X() + tileset->Width() - 1, offset.Y()), tileset->Height(), color);
70 if (tile.BlocksSouth()) {
71 sdl::HorizontalLine(dest, Vector<int>(offset.X(), offset.Y() + tileset->Height() - 1), tileset->Width(), color);
73 if (tile.BlocksWest()) {
74 sdl::VerticalLine(dest, offset, tileset->Height(), color);