diff options
Diffstat (limited to 'src/map.cpp')
| -rw-r--r-- | src/map.cpp | 25 |
1 files changed, 22 insertions, 3 deletions
| diff --git a/src/map.cpp b/src/map.cpp index d7c1e7e..4781231 100644 --- a/src/map.cpp +++ b/src/map.cpp | |||
| @@ -50,7 +50,18 @@ Map::Map(std::string_view name) : name_(name) { | |||
| 50 | tilesToStore.push_back(std::move(tile)); | 50 | tilesToStore.push_back(std::move(tile)); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | layers_.push_back(std::move(tilesToStore)); | 53 | bool above = false; |
| 54 | for (const tmx::Property& property : tileLayer.getProperties()) { | ||
| 55 | if (property.getName() == "above" && property.getBoolValue()) { | ||
| 56 | above = true; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | if (above) { | ||
| 61 | upperLayers_.push_back(std::move(tilesToStore)); | ||
| 62 | } else { | ||
| 63 | lowerLayers_.push_back(std::move(tilesToStore)); | ||
| 64 | } | ||
| 54 | } else if (layer->getType() == tmx::Layer::Type::Object) { | 65 | } else if (layer->getType() == tmx::Layer::Type::Object) { |
| 55 | const auto& objectLayer = layer->getLayerAs<tmx::ObjectGroup>(); | 66 | const auto& objectLayer = layer->getLayerAs<tmx::ObjectGroup>(); |
| 56 | 67 | ||
| @@ -137,9 +148,13 @@ Map::Map(std::string_view name) : name_(name) { | |||
| 137 | } | 148 | } |
| 138 | 149 | ||
| 139 | bool Map::isBlocked(int x, int y) const { | 150 | bool Map::isBlocked(int x, int y) const { |
| 151 | if (x < 0 || y < 0 || x >= mapSize_.w() || y >= mapSize_.h()) { | ||
| 152 | return false; | ||
| 153 | } | ||
| 154 | |||
| 140 | int i = x + y * mapSize_.w(); | 155 | int i = x + y * mapSize_.w(); |
| 141 | 156 | ||
| 142 | for (const std::vector<Tile>& layer : layers_) { | 157 | for (const std::vector<Tile>& layer : lowerLayers_) { |
| 143 | if (layer.at(i).blocked) { | 158 | if (layer.at(i).blocked) { |
| 144 | return true; | 159 | return true; |
| 145 | } | 160 | } |
| @@ -149,9 +164,13 @@ bool Map::isBlocked(int x, int y) const { | |||
| 149 | } | 164 | } |
| 150 | 165 | ||
| 151 | StepType Map::getStepType(int x, int y) const { | 166 | StepType Map::getStepType(int x, int y) const { |
| 167 | if (x < 0 || y < 0 || x >= mapSize_.w() || y >= mapSize_.h()) { | ||
| 168 | return StepType::none; | ||
| 169 | } | ||
| 170 | |||
| 152 | int i = x + y * mapSize_.w(); | 171 | int i = x + y * mapSize_.w(); |
| 153 | 172 | ||
| 154 | for (const std::vector<Tile>& layer : layers_) { | 173 | for (const std::vector<Tile>& layer : lowerLayers_) { |
| 155 | if (layer.at(i).step != StepType::none) { | 174 | if (layer.at(i).step != StepType::none) { |
| 156 | return layer.at(i).step; | 175 | return layer.at(i).step; |
| 157 | } | 176 | } |
