From: Daniel Karbach Date: Sun, 7 Oct 2012 12:40:20 +0000 (+0200) Subject: added temporary map transition implementation X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=d8d0982340fc10e5161251a4b50223fabc7b4431;p=l2e.git added temporary map transition implementation --- diff --git a/src/main.cpp b/src/main.cpp index 1507311..2a49ad5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -492,6 +492,12 @@ int main(int argc, char **argv) { map2.SetTriggers(triggers2, 1); map2.SetWidth(1); + triggers1[0].map = &map2; + triggers1[0].target = Vector(6, 2); + + triggers2[0].map = &map1; + triggers2[0].target = Vector(8, 3); + SDL_Surface *mapMaximImg(IMG_Load("test-data/maxim-map.png")); Sprite mapMaximSprite(mapMaximImg, 32, 64); SimpleAnimation mapMaximAnimation(&mapMaximSprite, (tileSize/walkSpeed) / 2 * 1000, 2, 0, 0, true); diff --git a/src/map/MapState.cpp b/src/map/MapState.cpp index 350a1f4..8c5ef6b 100644 --- a/src/map/MapState.cpp +++ b/src/map/MapState.cpp @@ -9,6 +9,7 @@ #include "Map.h" #include "Tile.h" +#include "Trigger.h" #include "../app/Application.h" #include "../app/Input.h" @@ -28,6 +29,7 @@ MapState::MapState(Map *map) , walkingSpeed(64) , nextDirection(-1) , afterLock(false) +, skipLock(false) , debug(false) { } @@ -183,9 +185,13 @@ bool MapState::CheckBlocking() const { } void MapState::OnGridLock() { - LockEntities(); - CheckMonster(); - CheckTrigger(); + if (skipLock) { + skipLock = false; + } else { + LockEntities(); + CheckMonster(); + CheckTrigger(); + } } void MapState::LockEntities() { @@ -223,7 +229,10 @@ void MapState::CheckMonster() { void MapState::CheckTrigger() { Trigger *trigger(map->TriggerAt(Vector(controlled->Position()))); if (trigger) { - // TODO: run trigger + // TODO: run trigger script + if (trigger->map) { + Transition(trigger->map, trigger->target); + } } } @@ -277,6 +286,19 @@ void MapState::StopFollowers(Entity &e) { } +void MapState::Transition(Map *newMap, const Vector &coordinates) { + Vector position(coordinates * map->Tileset()->Size()); + entities.clear(); + for (Entity *e(controlled); e; e = e->Follower()) { + e->Position() = position; + e->SetOrientation(controlled->GetOrientation()); + entities.push_back(e); + } + map = newMap; + skipLock = true; +} + + void MapState::Render(SDL_Surface *screen) { SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); diff --git a/src/map/MapState.h b/src/map/MapState.h index 4ba149d..ccdb51e 100644 --- a/src/map/MapState.h +++ b/src/map/MapState.h @@ -42,6 +42,8 @@ public: void SetWalkingSpeed(float s) { walkingSpeed = s; } + void Transition(Map *, const geometry::Vector &coordinates); + private: static bool ZCompare(const Entity *lhs, const Entity *rhs); @@ -69,6 +71,7 @@ private: float walkingSpeed; int nextDirection; bool afterLock; + bool skipLock; bool debug; }; diff --git a/src/map/Trigger.h b/src/map/Trigger.h index f1e9cb0..47f933b 100644 --- a/src/map/Trigger.h +++ b/src/map/Trigger.h @@ -8,6 +8,7 @@ #ifndef MAP_TRIGGER_H_ #define MAP_TRIGGER_H_ +#include "fwd.h" #include "../geometry/Vector.h" namespace map { @@ -28,6 +29,11 @@ public: private: geometry::Vector tilePosition; +// temporary members until scripting is implemented +public: + Map *map; + geometry::Vector target; + }; }