summaryrefslogtreecommitdiffstats
path: root/src/model/Map.hpp
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-09-25 18:39:03 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-09-25 18:39:03 +0200
commiteb40e3de7226d0005ce0a41c67c9355e675a489b (patch)
tree2ca2b4c14fcfa8c94370dfe0d192f82e41943b92 /src/model/Map.hpp
parentefa8640aabb3b4df31531ecd41ed1073dda63ed2 (diff)
downloadrpgedit-eb40e3de7226d0005ce0a41c67c9355e675a489b.tar
rpgedit-eb40e3de7226d0005ce0a41c67c9355e675a489b.zip
Add collision layer to maps and prevent movement into blocked areas
Diffstat (limited to 'src/model/Map.hpp')
-rw-r--r--src/model/Map.hpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/model/Map.hpp b/src/model/Map.hpp
index 421b487..abbf2f1 100644
--- a/src/model/Map.hpp
+++ b/src/model/Map.hpp
@@ -40,16 +40,23 @@ namespace RPGEdit {
namespace Model {
class Map {
+public:
+ enum CollisionType {
+ BLOCKED = 0,
+ EMPTY,
+ };
+
private:
std::vector<std::string> tileset;
size_t width, height;
+ std::vector<CollisionType> collision;
std::vector<std::vector<uint32_t>> tiles;
std::deque<Entity> entities;
Map(size_t width0, size_t height0, size_t layers)
- : width(width0), height(height0) {
+ : width(width0), height(height0), collision(width*height) {
for (size_t i = 0; i < layers; i++)
tiles.emplace_back(width*height);
}
@@ -83,6 +90,21 @@ public:
return tiles.size();
}
+ void setCollisionAt(size_t x, size_t y, CollisionType value) {
+ if (x >= width || y >= height)
+ throw std::range_error("Map::setTileAt: bad coordinates");
+
+ collision[y*width + x] = value;
+ }
+
+ CollisionType getCollisionAt(ssize_t x, ssize_t y) const {
+ if (x < 0 || (size_t)x >= width || y < 0 || (size_t)y >= height)
+ return BLOCKED;
+
+ return collision[y*width + x];
+ }
+
+
void setTileAt(size_t layer, size_t x, size_t y, uint32_t value) {
if (layer >= tiles.size() || x >= width || y >= height)
throw std::range_error("Map::setTileAt: bad coordinates");