diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-24 03:20:25 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-24 03:20:25 +0200 |
commit | 3c995acde81feae6c46a14fe7abbc6d2b434422b (patch) | |
tree | 34004193dfc64490662c519d5ef45e4c056d7690 /src/model | |
parent | ba321783e7f66068a5a5379992a8e081a70bf243 (diff) | |
download | rpgedit-3c995acde81feae6c46a14fe7abbc6d2b434422b.tar rpgedit-3c995acde81feae6c46a14fe7abbc6d2b434422b.zip |
Support multiple map layers, fix transparent tiles
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/Map.cpp | 13 | ||||
-rw-r--r-- | src/model/Map.hpp | 20 |
2 files changed, 23 insertions, 10 deletions
diff --git a/src/model/Map.cpp b/src/model/Map.cpp index db18baf..a770ee4 100644 --- a/src/model/Map.cpp +++ b/src/model/Map.cpp @@ -35,13 +35,22 @@ std::shared_ptr<Map> Map::load(__attribute__((unused)) const std::string &name) std::shared_ptr<Map> map(new Map(16, 16)); map->tileset.push_back("dirt"); + map->tileset.push_back("horizontal_bar"); + + for (int i = 0; i < 2; i++) + map->tiles.emplace_back(new uint32_t[16*16]); for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { if (4 <= i && i < 12 && 4 <= j && j < 12) - map->setTileAt(i, j, 1); + map->setTileAt(0, i, j, 1); + else + map->setTileAt(0, i, j, 0); + + if (4 <= i && i < 12 && j == 8) + map->setTileAt(1, i, j, 2); else - map->setTileAt(i, j, 0); + map->setTileAt(1, i, j, 0); } } 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<std::string> tileset; size_t width, height; - std::unique_ptr<uint32_t[]> tiles; + std::vector<std::unique_ptr<uint32_t[]>> tiles; std::shared_ptr<Entity> playerEntity; mutable std::deque<std::shared_ptr<Entity>> 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<Map> load(const std::string &name); |