4 #include "../graphics/Sprite.h"
5 #include "../loader/TypeDescription.h"
6 #include "../loader/Interpreter.h"
7 #include "../sdl/utility.h"
11 using geometry::Vector;
12 using loader::FieldDescription;
13 using loader::Interpreter;
14 using loader::TypeDescription;
27 Tile *Area::TileAt(const geometry::Vector<int> &offset) {
28 int tileIndex(offset.Y() * width + offset.X());
29 if (tileIndex < numTiles) {
30 return tiles +tileIndex;
36 const Tile *Area::TileAt(const geometry::Vector<int> &offset) const {
37 int tileIndex(offset.Y() * width + offset.X());
38 if (tileIndex < numTiles) {
39 return tiles +tileIndex;
46 void Area::Render(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector<int> &inOffset) const {
47 for (int i(0); i < numTiles; ++i) {
49 inOffset.X() + (i % width) * tileset->Width(),
50 inOffset.Y() + (i / width) * tileset->Height());
51 const Tile &tile(tiles[i]);
52 tileset->Draw(dest, offset, tile.Offset().X(), tile.Offset().Y());
56 void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector<int> &inOffset) const {
58 destRect.x = inOffset.X();
59 destRect.y = inOffset.Y();
60 destRect.w = Width() * tileset->Width();
61 destRect.h = Height() * tileset->Height();
62 sdl::OutlineRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF));
64 Uint32 color(SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
66 for (int i(0); i < numTiles; ++i) {
68 inOffset.X() + (i % width) * tileset->Width(),
69 inOffset.Y() + (i / width) * tileset->Height());
70 const Tile &tile(tiles[i]);
72 if (tile.BlocksNorth()) {
73 sdl::HorizontalLine(dest, offset, tileset->Width(), color);
75 if (tile.BlocksEast()) {
76 sdl::VerticalLine(dest, Vector<int>(offset.X() + tileset->Width() - 1, offset.Y()), tileset->Height(), color);
78 if (tile.BlocksSouth()) {
79 sdl::HorizontalLine(dest, Vector<int>(offset.X(), offset.Y() + tileset->Height() - 1), tileset->Width(), color);
81 if (tile.BlocksWest()) {
82 sdl::VerticalLine(dest, offset, tileset->Height(), color);
88 void Area::CreateTypeDescription() {
91 TypeDescription &td(TypeDescription::Create(TYPE_ID, "Area"));
92 td.SetConstructor(&Construct);
93 td.SetSize(sizeof(Area));
95 td.AddField("battlebg", FieldDescription(((char *)&a.battlebg) - ((char *)&a), Interpreter::IMAGE_ID).SetReferenced());
96 td.AddField("tiles", FieldDescription(((char *)&a.tiles) - ((char *)&a), Tile::TYPE_ID).SetReferenced().SetAggregate());
97 td.AddField("width", FieldDescription(((char *)&a.width) - ((char *)&a), Interpreter::NUMBER_ID));
100 void Area::Construct(void *data) {