diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-03-06 17:42:17 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-03-06 17:42:17 +0000 |
commit | 5dc6243dfc06924d9206b2987bb7ededaa87f8f1 (patch) | |
tree | 565b4c983e53eba75801a0bfc5a77264627527a7 /src | |
parent | 000bbf497024f5d9c9c7521c0a423f458641a32e (diff) | |
download | mana-5dc6243dfc06924d9206b2987bb7ededaa87f8f1.tar.gz mana-5dc6243dfc06924d9206b2987bb7ededaa87f8f1.tar.bz2 mana-5dc6243dfc06924d9206b2987bb7ededaa87f8f1.tar.xz mana-5dc6243dfc06924d9206b2987bb7ededaa87f8f1.zip |
Added collision tileset... last commit missed there files.
Diffstat (limited to 'src')
-rw-r--r-- | src/resources/mapreader.cpp | 25 | ||||
-rw-r--r-- | src/resources/mapreader.h | 5 |
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; }; |