diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-02-18 12:35:45 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-02-18 12:35:45 -0500 |
commit | e16fb5be90c889c371cbb0ca2444735c2e12073c (patch) | |
tree | cbaa20e14a34c460b6c9886f266c4b4b6f62ae87 /src/world.cpp | |
parent | ed08b673c50b076042d8f0c49501372168142764 (diff) | |
download | therapy-e16fb5be90c889c371cbb0ca2444735c2e12073c.tar.gz therapy-e16fb5be90c889c371cbb0ca2444735c2e12073c.tar.bz2 therapy-e16fb5be90c889c371cbb0ca2444735c2e12073c.zip |
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.
Diffstat (limited to 'src/world.cpp')
-rw-r--r-- | src/world.cpp | 58 |
1 files changed, 57 insertions, 1 deletions
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) | |||
63 | xmlFree(key); | 63 | xmlFree(key); |
64 | 64 | ||
65 | std::vector<int> mapTiles; | 65 | std::vector<int> mapTiles; |
66 | Map::Adjacent leftAdj; | ||
67 | Map::Adjacent rightAdj; | ||
68 | Map::Adjacent upAdj; | ||
69 | Map::Adjacent downAdj; | ||
66 | 70 | ||
67 | for (xmlNodePtr mapNode = node->xmlChildrenNode; | 71 | for (xmlNodePtr mapNode = node->xmlChildrenNode; |
68 | mapNode != nullptr; | 72 | mapNode != nullptr; |
@@ -82,6 +86,54 @@ World::World(std::string filename) | |||
82 | } | 86 | } |
83 | 87 | ||
84 | xmlFree(key); | 88 | xmlFree(key); |
89 | } else if (!xmlStrcmp( | ||
90 | mapNode->name, | ||
91 | reinterpret_cast<const xmlChar*>("adjacent"))) | ||
92 | { | ||
93 | key = getProp(mapNode, "type"); | ||
94 | std::string adjTypeStr(reinterpret_cast<char*>(key)); | ||
95 | xmlFree(key); | ||
96 | |||
97 | Map::Adjacent::Type adjType; | ||
98 | if (adjTypeStr == "wall") | ||
99 | { | ||
100 | adjType = Map::Adjacent::Type::wall; | ||
101 | } else if (adjTypeStr == "wrap") | ||
102 | { | ||
103 | adjType = Map::Adjacent::Type::wrap; | ||
104 | } else if (adjTypeStr == "warp") | ||
105 | { | ||
106 | adjType = Map::Adjacent::Type::warp; | ||
107 | } else if (adjTypeStr == "reverseWarp") | ||
108 | { | ||
109 | adjType = Map::Adjacent::Type::reverse; | ||
110 | } else { | ||
111 | throw std::logic_error("Invalid adjacency type"); | ||
112 | } | ||
113 | |||
114 | key = getProp(mapNode, "map"); | ||
115 | int adjMapId = atoi(reinterpret_cast<char*>(key)); | ||
116 | xmlFree(key); | ||
117 | |||
118 | key = getProp(mapNode, "dir"); | ||
119 | std::string adjDir(reinterpret_cast<char*>(key)); | ||
120 | xmlFree(key); | ||
121 | |||
122 | if (adjDir == "left") | ||
123 | { | ||
124 | leftAdj = {adjType, adjMapId}; | ||
125 | } else if (adjDir == "right") | ||
126 | { | ||
127 | rightAdj = {adjType, adjMapId}; | ||
128 | } else if (adjDir == "up") | ||
129 | { | ||
130 | upAdj = {adjType, adjMapId}; | ||
131 | } else if (adjDir == "down") | ||
132 | { | ||
133 | downAdj = {adjType, adjMapId}; | ||
134 | } else { | ||
135 | throw std::logic_error("Invalid adjacency direction"); | ||
136 | } | ||
85 | } | 137 | } |
86 | } | 138 | } |
87 | 139 | ||
@@ -91,7 +143,11 @@ World::World(std::string filename) | |||
91 | std::forward_as_tuple( | 143 | std::forward_as_tuple( |
92 | mapId, | 144 | mapId, |
93 | std::move(mapTiles), | 145 | std::move(mapTiles), |
94 | std::move(mapTitle))); | 146 | std::move(mapTitle), |
147 | leftAdj, | ||
148 | rightAdj, | ||
149 | upAdj, | ||
150 | downAdj)); | ||
95 | } | 151 | } |
96 | } | 152 | } |
97 | 153 | ||