From e16fb5be90c889c371cbb0ca2444735c2e12073c Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 18 Feb 2018 12:35:45 -0500 Subject: Implemented map adjacency This brings along with it the ability to move to different maps, for which the PlayingSystem and PlayableComponent were introduced. The PlayingSystem is a general overseer system that handles big picture stuff like initializing the player and changing maps. The PlayableComponent represents the player. While the ControllableComponent is also likely to always only be on the player entity, the two are distinct by separation of concerns. This also required a refactoring of how collisions are processed, because of a bug where the player can move to a new map when horizontal collisions are checked, and vertical collisions are skipped, causing the player to clip through the ground because the normal force was never handled. --- src/world.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) (limited to 'src/world.cpp') diff --git a/src/world.cpp b/src/world.cpp index 9b1e4f6..3b6bd41 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -63,6 +63,10 @@ World::World(std::string filename) xmlFree(key); std::vector mapTiles; + Map::Adjacent leftAdj; + Map::Adjacent rightAdj; + Map::Adjacent upAdj; + Map::Adjacent downAdj; for (xmlNodePtr mapNode = node->xmlChildrenNode; mapNode != nullptr; @@ -82,6 +86,54 @@ World::World(std::string filename) } xmlFree(key); + } else if (!xmlStrcmp( + mapNode->name, + reinterpret_cast("adjacent"))) + { + key = getProp(mapNode, "type"); + std::string adjTypeStr(reinterpret_cast(key)); + xmlFree(key); + + Map::Adjacent::Type adjType; + if (adjTypeStr == "wall") + { + adjType = Map::Adjacent::Type::wall; + } else if (adjTypeStr == "wrap") + { + adjType = Map::Adjacent::Type::wrap; + } else if (adjTypeStr == "warp") + { + adjType = Map::Adjacent::Type::warp; + } else if (adjTypeStr == "reverseWarp") + { + adjType = Map::Adjacent::Type::reverse; + } else { + throw std::logic_error("Invalid adjacency type"); + } + + key = getProp(mapNode, "map"); + int adjMapId = atoi(reinterpret_cast(key)); + xmlFree(key); + + key = getProp(mapNode, "dir"); + std::string adjDir(reinterpret_cast(key)); + xmlFree(key); + + if (adjDir == "left") + { + leftAdj = {adjType, adjMapId}; + } else if (adjDir == "right") + { + rightAdj = {adjType, adjMapId}; + } else if (adjDir == "up") + { + upAdj = {adjType, adjMapId}; + } else if (adjDir == "down") + { + downAdj = {adjType, adjMapId}; + } else { + throw std::logic_error("Invalid adjacency direction"); + } } } @@ -91,7 +143,11 @@ World::World(std::string filename) std::forward_as_tuple( mapId, std::move(mapTiles), - std::move(mapTitle))); + std::move(mapTitle), + leftAdj, + rightAdj, + upAdj, + downAdj)); } } -- cgit 1.4.1