]> git.localhorst.tv Git - l2e.git/commitdiff
added temporary map transition implementation
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 7 Oct 2012 12:40:20 +0000 (14:40 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 7 Oct 2012 12:40:20 +0000 (14:40 +0200)
src/main.cpp
src/map/MapState.cpp
src/map/MapState.h
src/map/Trigger.h

index 15073111afd3bc5e94356c149ece0edb61a37ee9..2a49ad585f50c09a8d5e487dc9bba6adf5b06079 100644 (file)
@@ -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<int>(6, 2);
+
+               triggers2[0].map = &map1;
+               triggers2[0].target = Vector<int>(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);
index 350a1f48f8be2813585fef2fbc8233b5f4f06000..8c5ef6bcf1c53ec612c3ba86d043b003127563b8 100644 (file)
@@ -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<int>(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<int> &coordinates) {
+       Vector<int> 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));
 
index 4ba149db1d96c3e05749c4a5b32f411b5938dfc5..ccdb51e7fef0c07477640387a4e828f7dcf182ee 100644 (file)
@@ -42,6 +42,8 @@ public:
 
        void SetWalkingSpeed(float s) { walkingSpeed = s; }
 
+       void Transition(Map *, const geometry::Vector<int> &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;
 
 };
index f1e9cb0089c189f7eb14d921c1a13947cdc1e2a4..47f933be42263dc529ed3a7c6d203575a4edf26f 100644 (file)
@@ -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<int> tilePosition;
 
+// temporary members until scripting is implemented
+public:
+       Map *map;
+       geometry::Vector<int> target;
+
 };
 
 }