Trigger triggers1[1];
triggers1[0].SetTilePosition(Vector<int>(8, 3));
+ triggers1[0].SetType(Trigger::TYPE_NORTH);
SDL_Surface *tilesetImg(IMG_Load("test-data/tileset.png"));
Sprite tileset(tilesetImg, tileSize, tileSize);
Trigger triggers2[1];
triggers2[0].SetTilePosition(Vector<int>(6, 2));
+ triggers2[0].SetType(Trigger::TYPE_SOUTH);
Map map2;
map2.SetAreas(areas2, 1);
#include "Tile.h"
#include "Trigger.h"
#include "../graphics/Sprite.h"
+#include "../sdl/utility.h"
#include <stdexcept>
}
for (int i(0); i < numTriggers; ++i) {
Vector<int> 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<int>(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<int>(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;
+ case Trigger::TYPE_BUTTON:
+ break;
+ }
}
}
return false;
} else {
LockEntities();
- return CheckMonster() || CheckTrigger();
+ return CheckMonster() || CheckLockTrigger();
}
}
return false;
}
-bool MapState::CheckTrigger() {
+bool MapState::CheckLockTrigger() {
Trigger *trigger(map->TriggerAt(Vector<int>(controlled->Position())));
- if (trigger) {
- // TODO: run trigger script
- if (trigger->map) {
- ctrl->PushState(new ColorFade(this, 0, 500, true));
- ctrl->PushState(new TransitionState(this, trigger->map, trigger->target));
- ColorFade *fadeOut(new ColorFade(this, 0, 500, false));
- fadeOut->SetLeadOutTime(500);
- ctrl->PushState(fadeOut);
- return true;
- }
- }
- return false;
+ if (!trigger || trigger->GetType() != Trigger::TYPE_CONTACT) return false;
+ RunTrigger(*trigger);
+ return true;
}
void MapState::OnMove(bool realMove) {
+ if (CheckMoveTrigger()) {
+ return;
+ }
// TODO: evaluate monster movements
if (realMove) {
UpdateFollower(*controlled);
}
}
+bool MapState::CheckMoveTrigger() {
+ Trigger *trigger(map->TriggerAt(Vector<int>(controlled->Position())));
+ if (!trigger || int(trigger->GetType()) != nextDirection) return false;
+ RunTrigger(*trigger);
+ return true;
+}
+
+void MapState::RunTrigger(Trigger &trigger) {
+ // TODO: run trigger script
+ if (trigger.map) {
+ ctrl->PushState(new ColorFade(this, 0, 500, true));
+ ctrl->PushState(new TransitionState(this, trigger.map, trigger.target));
+ ColorFade *fadeOut(new ColorFade(this, 0, 500, false));
+ fadeOut->SetLeadOutTime(500);
+ ctrl->PushState(fadeOut);
+ }
+}
+
void MapState::UpdateFollower(Entity &e) {
if (!e.Follower()) return;
void LockEntities();
bool CheckMonster();
- bool CheckTrigger();
+
+ bool CheckLockTrigger();
+ bool CheckMoveTrigger();
+ void RunTrigger(Trigger &);
private:
common::GameConfig *game;
namespace map {
-Trigger::Trigger() {
+Trigger::Trigger()
+: type(TYPE_CONTACT)
+, map(0) {
}
#ifndef MAP_TRIGGER_H_
#define MAP_TRIGGER_H_
+#include "Entity.h"
#include "fwd.h"
#include "../geometry/Vector.h"
Trigger();
~Trigger() { }
+ enum Type {
+ TYPE_NORTH = Entity::ORIENTATION_NORTH,
+ TYPE_EAST = Entity::ORIENTATION_EAST,
+ TYPE_SOUTH = Entity::ORIENTATION_SOUTH,
+ TYPE_WEST = Entity::ORIENTATION_WEST,
+ TYPE_CONTACT,
+ };
+
public:
const geometry::Vector<int> &TilePosition() const { return tilePosition; }
+ Type GetType() const { return type; }
// temporary setters
public:
void SetTilePosition(const geometry::Vector<int> &p) { tilePosition = p; }
+ void SetType(Type t) { type = t; }
private:
geometry::Vector<int> tilePosition;
+ Type type;
// temporary members until scripting is implemented
public: