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);
#include "Map.h"
#include "Tile.h"
+#include "Trigger.h"
#include "../app/Application.h"
#include "../app/Input.h"
, walkingSpeed(64)
, nextDirection(-1)
, afterLock(false)
+, skipLock(false)
, debug(false) {
}
}
void MapState::OnGridLock() {
- LockEntities();
- CheckMonster();
- CheckTrigger();
+ if (skipLock) {
+ skipLock = false;
+ } else {
+ LockEntities();
+ CheckMonster();
+ CheckTrigger();
+ }
}
void MapState::LockEntities() {
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);
+ }
}
}
}
+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));
void SetWalkingSpeed(float s) { walkingSpeed = s; }
+ void Transition(Map *, const geometry::Vector<int> &coordinates);
+
private:
static bool ZCompare(const Entity *lhs, const Entity *rhs);
float walkingSpeed;
int nextDirection;
bool afterLock;
+ bool skipLock;
bool debug;
};
#ifndef MAP_TRIGGER_H_
#define MAP_TRIGGER_H_
+#include "fwd.h"
#include "../geometry/Vector.h"
namespace map {
private:
geometry::Vector<int> tilePosition;
+// temporary members until scripting is implemented
+public:
+ Map *map;
+ geometry::Vector<int> target;
+
};
}