summary refs log tree commit diff stats
path: root/src/map.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-22 22:46:44 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-22 22:46:44 -0500
commit3ecf5bbc1c81908bfd3355999a37e8e96e15b8b5 (patch)
tree3cb83a80a1f315fb8bc3a918782be2f02d2799ce /src/map.cpp
parent5e8522258412d05994cc5efa678a1d713cdae718 (diff)
downloadtanetane-3ecf5bbc1c81908bfd3355999a37e8e96e15b8b5.tar.gz
tanetane-3ecf5bbc1c81908bfd3355999a37e8e96e15b8b5.tar.bz2
tanetane-3ecf5bbc1c81908bfd3355999a37e8e96e15b8b5.zip
Generalized upper/lower layer map rendering
Map layers can have a flag on them that specifies that they should be rendered as part of the upper set (rendered above the normal sprite layer but below the above sprite layer).

Also added map connections between hallucination_interior and hallucination_cliff. And named the layers in the map files bc why not.
Diffstat (limited to 'src/map.cpp')
-rw-r--r--src/map.cpp25
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
139bool Map::isBlocked(int x, int y) const { 150bool 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
151StepType Map::getStepType(int x, int y) const { 166StepType 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 }