From 3c995acde81feae6c46a14fe7abbc6d2b434422b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 24 Sep 2014 03:20:25 +0200 Subject: Support multiple map layers, fix transparent tiles --- src/model/Map.hpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/model/Map.hpp') diff --git a/src/model/Map.hpp b/src/model/Map.hpp index 9d4eded..423c91d 100644 --- a/src/model/Map.hpp +++ b/src/model/Map.hpp @@ -44,14 +44,14 @@ private: std::vector tileset; size_t width, height; - std::unique_ptr tiles; + std::vector> tiles; std::shared_ptr playerEntity; mutable std::deque> entities; Map(size_t width0, size_t height0) - : width(width0), height(height0), tiles(new uint32_t[width*height]) { + : width(width0), height(height0) { } public: @@ -79,18 +79,22 @@ public: return height; } - void setTileAt(size_t x, size_t y, uint32_t value) { - if (x >= width || y >= height) + size_t getLayerCount() const { + return tiles.size(); + } + + 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"); - tiles[y*width + x] = value; + tiles[layer][y*width + x] = value; } - uint32_t getTileAt(ssize_t x, ssize_t y) const { - if (x < 0 || (size_t)x >= width || y < 0 || (size_t)y >= height) + uint32_t getTileAt(size_t layer, ssize_t x, ssize_t y) const { + if (layer >= tiles.size() || x < 0 || (size_t)x >= width || y < 0 || (size_t)y >= height) return 0; - return tiles[y*width + x]; + return tiles[layer][y*width + x]; } static std::shared_ptr load(const std::string &name); -- cgit v1.2.3