4 * Created on: Sep 26, 2012
11 #include "../graphics/Sprite.h"
12 #include "../sdl/utility.h"
16 using geometry::Vector;
29 Tile *Area::TileAt(const geometry::Vector<int> &offset) {
30 int tileIndex(offset.Y() * width + offset.X());
31 if (tileIndex < numTiles) {
32 return tiles +tileIndex;
38 const Tile *Area::TileAt(const geometry::Vector<int> &offset) const {
39 int tileIndex(offset.Y() * width + offset.X());
40 if (tileIndex < numTiles) {
41 return tiles +tileIndex;
48 void Area::Render(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector<int> &inOffset) const {
49 for (int i(0); i < numTiles; ++i) {
51 inOffset.X() + (i % width) * tileset->Width(),
52 inOffset.Y() + (i / width) * tileset->Height());
53 const Tile &tile(tiles[i]);
54 tileset->Draw(dest, offset, tile.Offset().X(), tile.Offset().Y());
58 void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector<int> &inOffset) const {
60 destRect.x = inOffset.X();
61 destRect.y = inOffset.Y();
62 destRect.w = Width() * tileset->Width();
63 destRect.h = Height() * tileset->Height();
64 sdl::OutlineRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF));
66 Uint32 color(SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
68 for (int i(0); i < numTiles; ++i) {
70 inOffset.X() + (i % width) * tileset->Width(),
71 inOffset.Y() + (i / width) * tileset->Height());
72 const Tile &tile(tiles[i]);
74 if (tile.BlocksNorth()) {
75 sdl::HorizontalLine(dest, offset, tileset->Width(), color);
77 if (tile.BlocksEast()) {
78 sdl::VerticalLine(dest, Vector<int>(offset.X() + tileset->Width() - 1, offset.Y()), tileset->Height(), color);
80 if (tile.BlocksSouth()) {
81 sdl::HorizontalLine(dest, Vector<int>(offset.X(), offset.Y() + tileset->Height() - 1), tileset->Width(), color);
83 if (tile.BlocksWest()) {
84 sdl::VerticalLine(dest, offset, tileset->Height(), color);