X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmap%2FArea.cpp;h=6299290a6a98057dfcbb3257675fcd07bdb37324;hb=HEAD;hp=9c066d646f021a0b8d0d644bb6806fbb5f98622d;hpb=ed792d6d00d822384d79d049e644e372f7c3b4cd;p=l2e.git diff --git a/src/map/Area.cpp b/src/map/Area.cpp index 9c066d6..6299290 100644 --- a/src/map/Area.cpp +++ b/src/map/Area.cpp @@ -1,31 +1,40 @@ -/* - * Area.cpp - * - * Created on: Sep 26, 2012 - * Author: holy - */ - #include "Area.h" #include "Tile.h" #include "../graphics/Sprite.h" +#include "../loader/TypeDescription.h" +#include "../loader/Interpreter.h" +#include "../math/Vector.h" #include "../sdl/utility.h" #include -using geometry::Vector; +using math::Vector; +using loader::FieldDescription; +using loader::Interpreter; +using loader::TypeDescription; namespace map { Area::Area() -: tiles(0) +: battlebg(0) +, tiles(0) , numTiles(0) , width(0) { } -const Tile *Area::TileAt(const geometry::Vector &offset) const { +Tile *Area::TileAt(const math::Vector &offset) { + int tileIndex(offset.Y() * width + offset.X()); + if (tileIndex < numTiles) { + return tiles +tileIndex; + } else { + return 0; + } +} + +const Tile *Area::TileAt(const math::Vector &offset) const { int tileIndex(offset.Y() * width + offset.X()); if (tileIndex < numTiles) { return tiles +tileIndex; @@ -35,13 +44,19 @@ const Tile *Area::TileAt(const geometry::Vector &offset) const { } -void Area::Render(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector &inOffset) const { +void Area::Render( + SDL_Surface *dest, + const graphics::Sprite *tileset, + const Vector &inOffset, + unsigned int frame) const { for (int i(0); i < numTiles; ++i) { Vector offset( inOffset.X() + (i % width) * tileset->Width(), inOffset.Y() + (i / width) * tileset->Height()); const Tile &tile(tiles[i]); - tileset->Draw(dest, offset, tile.Offset().X(), tile.Offset().Y()); + tileset->Draw(dest, offset, + tile.Offset().X(), + tile.Offset().Y() + (frame % tile.NumFrames())); } } @@ -73,7 +88,32 @@ void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const if (tile.BlocksWest()) { sdl::VerticalLine(dest, offset, tileset->Height(), color); } + if (tile.IsLadder()) { + SDL_Rect rect; + rect.x = offset.X() + (tileset->Width() / 2) - 2; + rect.y = offset.Y(); + rect.w = 4; + rect.h = tileset->Height(); + SDL_FillRect(dest, &rect, color); + } } } + +void Area::CreateTypeDescription() { + Area a; + + TypeDescription &td(TypeDescription::Create(TYPE_ID, "Area")); + td.SetConstructor(&Construct); + td.SetSize(sizeof(Area)); + + td.AddField("battlebg", FieldDescription(((char *)&a.battlebg) - ((char *)&a), Interpreter::IMAGE_ID).SetReferenced()); + td.AddField("tiles", FieldDescription(((char *)&a.tiles) - ((char *)&a), Tile::TYPE_ID).SetAggregate()); + td.AddField("width", FieldDescription(((char *)&a.width) - ((char *)&a), Interpreter::NUMBER_ID)); +} + +void Area::Construct(void *data) { + new (data) Area; +} + }