diff options
Diffstat (limited to 'src/model/Map.hpp')
-rw-r--r-- | src/model/Map.hpp | 24 |
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"); |