#include "map/Map.h"
#include "map/MapState.h"
#include "map/Tile.h"
+#include "map/Trigger.h"
#include "sdl/InitImage.h"
#include "sdl/InitScreen.h"
#include "sdl/InitSDL.h"
using map::Map;
using map::MapState;
using map::Tile;
+using map::Trigger;
using sdl::InitImage;
using sdl::InitScreen;
using sdl::InitSDL;
tiles[62].SetOffset(Vector<int>(1, 1));
tiles[63].SetOffset(Vector<int>(1, 1));
- Area area;
- area.SetTiles(tiles, 64);
- area.SetWidth(8);
+ Area areas[1];
+ areas[0].SetTiles(tiles, 64);
+ areas[0].SetWidth(8);
+
+ Trigger triggers[1];
+ triggers[0].SetTilePosition(Vector<int>(2, 0));
SDL_Surface *tilesetImg(IMG_Load("test-data/tileset.png"));
Sprite tileset(tilesetImg, tileSize, tileSize);
Map map;
- map.SetAreas(&area, 1);
+ map.SetAreas(areas, 1);
map.SetTileset(&tileset);
+ map.SetTriggers(triggers, 1);
map.SetWidth(1);
SDL_Surface *mapMaximImg(IMG_Load("test-data/maxim-map.png"));
#include "Map.h"
#include "Area.h"
+#include "Trigger.h"
#include "../graphics/Sprite.h"
#include <stdexcept>
: tileset(0)
, areas(0)
, numAreas(0)
+, triggers(0)
+, numTriggers(0)
, width(0) {
}
return area.TileAt(tileOffset);
}
+Trigger *Map::TriggerAt(const geometry::Vector<int> &offset) {
+ // TODO: add support for multiple triggers on a tile?
+ Vector<int> tilePosition(offset.X() / tileset->Width(), offset.Y() / tileset->Height());
+ for (Trigger *i(triggers); i != triggers + numTriggers; ++i) {
+ if (i->TilePosition() == tilePosition) {
+ return i;
+ }
+ }
+ return 0;
+}
+
void Map::Render(SDL_Surface *dest, const Vector<int> &inOffset) const {
// TODO: skip invisible areas
const graphics::Sprite *Tileset() const { return tileset; }
const Area &AreaAt(const geometry::Vector<int> &) const;
const Tile &TileAt(const geometry::Vector<int> &) const;
+ Trigger *TriggerAt(const geometry::Vector<int> &);
void Render(SDL_Surface *dest, const geometry::Vector<int> &offset) const;
// temporary setters
public:
void SetTileset(const graphics::Sprite *t) { tileset = t; }
- void SetAreas(const Area *a, int num) { areas = a; numAreas = num; }
+ void SetAreas(Area *a, int num) { areas = a; numAreas = num; }
+ void SetTriggers(Trigger *t, int num) { triggers = t; numTriggers = num; }
void SetWidth(int w) { width = w; }
private:
const graphics::Sprite *tileset;
- const Area *areas;
+ Area *areas;
int numAreas;
+ Trigger *triggers;
+ int numTriggers;
int width;
};
namespace map {
-MapState::MapState(const Map *map)
+MapState::MapState(Map *map)
: map(map)
, controlled(0)
, tempTarget(20, 20)
}
void MapState::OnGridLock() {
- // TODO: check for adjacent monsters and triggers on the current tile
+ Trigger *trigger(map->TriggerAt(Vector<int>(controlled->Position())));
+ if (trigger) {
+ // TODO: run trigger
+ }
+ // TODO: check for adjacent monsters
// TODO: force all entities into their grid positions?
}
: public app::State {
public:
- explicit MapState(const Map *);
+ explicit MapState(Map *);
virtual ~MapState() { }
public:
void OnMove();
private:
- const Map *map;
+ Map *map;
Entity *controlled;
geometry::Vector<float> tempTarget;
geometry::Vector<int> lastLock;