4 #include "../graphics/Sprite.h"
5 #include "../loader/TypeDescription.h"
6 #include "../loader/Interpreter.h"
7 #include "../math/Vector.h"
8 #include "../sdl/utility.h"
13 using loader::FieldDescription;
14 using loader::Interpreter;
15 using loader::TypeDescription;
28 Tile *Area::TileAt(const math::Vector<int> &offset) {
29 int tileIndex(offset.Y() * width + offset.X());
30 if (tileIndex < numTiles) {
31 return tiles +tileIndex;
37 const Tile *Area::TileAt(const math::Vector<int> &offset) const {
38 int tileIndex(offset.Y() * width + offset.X());
39 if (tileIndex < numTiles) {
40 return tiles +tileIndex;
49 const graphics::Sprite *tileset,
50 const Vector<int> &inOffset,
51 unsigned int frame) const {
52 for (int i(0); i < numTiles; ++i) {
54 inOffset.X() + (i % width) * tileset->Width(),
55 inOffset.Y() + (i / width) * tileset->Height());
56 const Tile &tile(tiles[i]);
57 tileset->Draw(dest, offset,
59 tile.Offset().Y() + (frame % tile.NumFrames()));
63 void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector<int> &inOffset) const {
65 destRect.x = inOffset.X();
66 destRect.y = inOffset.Y();
67 destRect.w = Width() * tileset->Width();
68 destRect.h = Height() * tileset->Height();
69 sdl::OutlineRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF));
71 Uint32 color(SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
73 for (int i(0); i < numTiles; ++i) {
75 inOffset.X() + (i % width) * tileset->Width(),
76 inOffset.Y() + (i / width) * tileset->Height());
77 const Tile &tile(tiles[i]);
79 if (tile.BlocksNorth()) {
80 sdl::HorizontalLine(dest, offset, tileset->Width(), color);
82 if (tile.BlocksEast()) {
83 sdl::VerticalLine(dest, Vector<int>(offset.X() + tileset->Width() - 1, offset.Y()), tileset->Height(), color);
85 if (tile.BlocksSouth()) {
86 sdl::HorizontalLine(dest, Vector<int>(offset.X(), offset.Y() + tileset->Height() - 1), tileset->Width(), color);
88 if (tile.BlocksWest()) {
89 sdl::VerticalLine(dest, offset, tileset->Height(), color);
91 if (tile.IsLadder()) {
93 rect.x = offset.X() + (tileset->Width() / 2) - 2;
96 rect.h = tileset->Height();
97 SDL_FillRect(dest, &rect, color);
103 void Area::CreateTypeDescription() {
106 TypeDescription &td(TypeDescription::Create(TYPE_ID, "Area"));
107 td.SetConstructor(&Construct);
108 td.SetSize(sizeof(Area));
110 td.AddField("battlebg", FieldDescription(((char *)&a.battlebg) - ((char *)&a), Interpreter::IMAGE_ID).SetReferenced());
111 td.AddField("tiles", FieldDescription(((char *)&a.tiles) - ((char *)&a), Tile::TYPE_ID).SetAggregate());
112 td.AddField("width", FieldDescription(((char *)&a.width) - ((char *)&a), Interpreter::NUMBER_ID));
115 void Area::Construct(void *data) {