X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmap%2FArea.cpp;h=6299290a6a98057dfcbb3257675fcd07bdb37324;hb=dc275497c592669dda75645604a9b35d32f63e90;hp=0b25a04bd7b512e9ca1f913856ff410f602b5667;hpb=07cdc452aeaad73ca9f8f9a3cf9868d2b6c9d5b3;p=l2e.git diff --git a/src/map/Area.cpp b/src/map/Area.cpp index 0b25a04..6299290 100644 --- a/src/map/Area.cpp +++ b/src/map/Area.cpp @@ -1,50 +1,75 @@ -/* - * 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]; + return tiles +tileIndex; } else { - throw std::out_of_range("tile index out of range"); + return 0; } } -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())); } } void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector &inOffset) const { + SDL_Rect destRect; + destRect.x = inOffset.X(); + destRect.y = inOffset.Y(); + destRect.w = Width() * tileset->Width(); + destRect.h = Height() * tileset->Height(); + sdl::OutlineRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0x00, 0xFF)); + + Uint32 color(SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00)); + for (int i(0); i < numTiles; ++i) { Vector offset( inOffset.X() + (i % width) * tileset->Width(), @@ -52,41 +77,43 @@ void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const const Tile &tile(tiles[i]); if (tile.BlocksNorth()) { - SDL_Rect destRect; - destRect.x = offset.X(); - destRect.y = offset.Y(); - destRect.w = tileset->Width(); - destRect.h = 1; - SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00)); + sdl::HorizontalLine(dest, offset, tileset->Width(), color); } - if (tile.BlocksEast()) { - SDL_Rect destRect; - destRect.x = offset.X() + tileset->Width() - 1; - destRect.y = offset.Y(); - destRect.w = 1; - destRect.h = tileset->Height(); - SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00)); + sdl::VerticalLine(dest, Vector(offset.X() + tileset->Width() - 1, offset.Y()), tileset->Height(), color); } - if (tile.BlocksSouth()) { - SDL_Rect destRect; - destRect.x = offset.X(); - destRect.y = offset.Y() + tileset->Height() - 1; - destRect.w = tileset->Width(); - destRect.h = 1; - SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00)); + sdl::HorizontalLine(dest, Vector(offset.X(), offset.Y() + tileset->Height() - 1), tileset->Width(), color); } - if (tile.BlocksWest()) { - SDL_Rect destRect; - destRect.x = offset.X(); - destRect.y = offset.Y(); - destRect.w = 1; - destRect.h = tileset->Height(); - SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00)); + 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; +} + }