X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmap%2FMap.cpp;h=85fbd22ad01156db0ae078364d116a5454cde0c9;hb=e1dab8a680a76f8621e967a693dbf2b481ba8f75;hp=a9e11df7e9064627cb4388b0696e78eada8c92b8;hpb=0ad5ca97b5df217329bc319d62564a9f46ba11d7;p=l2e.git diff --git a/src/map/Map.cpp b/src/map/Map.cpp index a9e11df..85fbd22 100644 --- a/src/map/Map.cpp +++ b/src/map/Map.cpp @@ -1,20 +1,21 @@ -/* - * Map.cpp - * - * Created on: Sep 29, 2012 - * Author: holy - */ - #include "Map.h" #include "Area.h" #include "Tile.h" #include "Trigger.h" #include "../graphics/Sprite.h" +#include "../loader/Interpreter.h" +#include "../loader/TypeDescription.h" +#include "../math/Vector.h" +#include "../sdl/utility.h" #include -using geometry::Vector; +using math::Vector; +using graphics::Sprite; +using loader::FieldDescription; +using loader::Interpreter; +using loader::TypeDescription; namespace map { @@ -76,7 +77,7 @@ const Tile *Map::TileAt(const Vector &offset) const { } } -Trigger *Map::TriggerAt(const geometry::Vector &offset) { +Trigger *Map::TriggerAt(const math::Vector &offset) { // TODO: add support for multiple triggers on a tile? Vector coords(TileCoordinates(offset)); for (Trigger *i(triggers); i != triggers + numTriggers; ++i) { @@ -87,7 +88,7 @@ Trigger *Map::TriggerAt(const geometry::Vector &offset) { return 0; } -SDL_Surface *Map::BattleBackgroundAt(const geometry::Vector &position) { +SDL_Surface *Map::BattleBackgroundAt(const math::Vector &position) { Tile *tile(TileAt(position)); if (tile && tile->BattleBackground()) { return tile->BattleBackground(); @@ -104,12 +105,15 @@ Vector Map::TileCoordinates(const Vector &position) const { } -void Map::Render(SDL_Surface *dest, const Vector &inOffset) const { +void Map::Render( + SDL_Surface *dest, + const Vector &inOffset, + unsigned int frame) const { // TODO: skip invisible areas for (int i(0); i < numAreas; ++i) { const Area &area(areas[i]); Vector offset(inOffset + Vector::FromIndex(i, width) * area.Size() * tileset->Size()); - area.Render(dest, tileset, offset); + area.Render(dest, tileset, offset, frame); } } @@ -122,13 +126,50 @@ void Map::RenderDebug(SDL_Surface *dest, const Vector &inOffset) const { } for (int i(0); i < numTriggers; ++i) { Vector offset((triggers[i].TilePosition() * tileset->Size()) + inOffset); - SDL_Rect destRect; - destRect.x = offset.X() + (tileset->Width() / 4); - destRect.y = offset.Y() + (tileset->Height() / 4); - destRect.w = tileset->Width() / 2; - destRect.h = tileset->Height() / 2; - SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0xFF, 0xFF)); + switch (triggers[i].GetType()) { + case Trigger::TYPE_NORTH: + sdl::HorizontalLine(dest, offset + (tileset->Size() / 4), tileset->Width() / 2, SDL_MapRGB(dest->format, 0x00, 0xFF, 0xFF)); + break; + case Trigger::TYPE_EAST: + sdl::VerticalLine(dest, offset + Vector(tileset->Width() * 3 / 4, tileset->Height() / 4), tileset->Height() / 2, SDL_MapRGB(dest->format, 0x00, 0xFF, 0xFF)); + break; + case Trigger::TYPE_SOUTH: + sdl::HorizontalLine(dest, offset + Vector(tileset->Width() / 4, tileset->Height() * 3 / 4), tileset->Width() / 2, SDL_MapRGB(dest->format, 0x00, 0xFF, 0xFF)); + break; + case Trigger::TYPE_WEST: + sdl::VerticalLine(dest, offset + (tileset->Size() / 4), tileset->Width() / 2, SDL_MapRGB(dest->format, 0x00, 0xFF, 0xFF)); + break; + case Trigger::TYPE_CONTACT: { + SDL_Rect destRect; + destRect.x = offset.X() + (tileset->Width() / 4); + destRect.y = offset.Y() + (tileset->Height() / 4); + destRect.w = tileset->Width() / 2; + destRect.h = tileset->Height() / 2; + SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0x00, 0xFF, 0xFF)); + } + break; + } } } + +void Map::CreateTypeDescription() { + Map m; + + TypeDescription &td(TypeDescription::Create(TYPE_ID, "Map")); + td.SetConstructor(&Construct); + td.SetSize(sizeof(Map)); + + td.AddField("tileset", FieldDescription(((char *)&m.tileset) - ((char *)&m), Sprite::TYPE_ID).SetReferenced()); + td.AddField("battlebg", FieldDescription(((char *)&m.battlebg) - ((char *)&m), Interpreter::IMAGE_ID).SetReferenced()); + td.AddField("areas", FieldDescription(((char *)&m.areas) - ((char *)&m), Area::TYPE_ID).SetAggregate()); + td.AddField("triggers", FieldDescription(((char *)&m.triggers) - ((char *)&m), Trigger::TYPE_ID).SetAggregate()); + td.AddField("entities", FieldDescription(((char *)&m.entities) - ((char *)&m), Entity::TYPE_ID).SetAggregate()); + td.AddField("width", FieldDescription(((char *)&m.width) - ((char *)&m), Interpreter::NUMBER_ID)); +} + +void Map::Construct(void *data) { + new (data) Map; +} + }