summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/resources/mapreader.cpp25
-rw-r--r--src/resources/mapreader.h5
2 files changed, 27 insertions, 3 deletions
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index b28515c1..20438c9d 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -176,8 +176,15 @@ void MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
if (xmlStrEqual(n2->name, BAD_CAST "tile") && y < h)
{
int gid = getProperty(n2, "gid", -1);
- if (layer == 0) map->setWalk(x, y, true);
- map->setTile(x, y, layer, getTileWithGid(gid));
+ if (layer == 3)
+ {
+ Tileset *set = getTilesetWithGid(gid);
+ map->setWalk(x, y,
+ !set || (gid - set->getFirstGid() == 0));
+ }
+ else if (layer < 3) {
+ map->setTile(x, y, layer, getTileWithGid(gid));
+ }
x++;
if (x == w) {x = 0; y++;}
@@ -257,6 +264,18 @@ int MapReader::getProperty(xmlNodePtr node, const char* name, int def)
Image *MapReader::getTileWithGid(int gid)
{
std::vector<Tileset*>::iterator i;
+ Tileset *set = getTilesetWithGid(gid);
+
+ if (set) {
+ return set->spriteset[gid - set->getFirstGid()];
+ }
+
+ return NULL;
+}
+
+Tileset *MapReader::getTilesetWithGid(int gid)
+{
+ std::vector<Tileset*>::iterator i;
Tileset *set = NULL;
// Find the tileset with the highest firstGid below/eq to gid
@@ -272,7 +291,7 @@ Image *MapReader::getTileWithGid(int gid)
if (set && (gid - set->getFirstGid()) < (int)set->spriteset.size())
{
- return set->spriteset[gid - set->getFirstGid()];
+ return set;
}
return NULL;
diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h
index 69c531de..59270f25 100644
--- a/src/resources/mapreader.h
+++ b/src/resources/mapreader.h
@@ -89,6 +89,11 @@ class MapReader
*/
static Image *getTileWithGid(int gid);
+ /**
+ * Finds the tile set that a tile with the given global id is part of.
+ */
+ static Tileset *MapReader::getTilesetWithGid(int gid);
+
static std::vector<Tileset*> tilesets;
};