diff options
-rw-r--r-- | src/transform_system.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/transform_system.cpp b/src/transform_system.cpp index 71b3a4f..055f546 100644 --- a/src/transform_system.cpp +++ b/src/transform_system.cpp | |||
@@ -57,9 +57,12 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i curLoc, vec2 | |||
57 | 57 | ||
58 | vec2i mapBounds = map.getMapSize() * map.getTileSize(); | 58 | vec2i mapBounds = map.getMapSize() * map.getTileSize(); |
59 | 59 | ||
60 | // First check horizontal movement only. | ||
61 | vec2i horizMovement = { newLoc.x(), curLoc.y() }; | ||
62 | |||
60 | vec2i oldColUL = curLoc + sprite.collisionOffset; | 63 | vec2i oldColUL = curLoc + sprite.collisionOffset; |
61 | vec2i oldColDR = oldColUL + sprite.collisionSize; | 64 | vec2i oldColDR = oldColUL + sprite.collisionSize; |
62 | vec2i newColUL = newLoc + sprite.collisionOffset; | 65 | vec2i newColUL = horizMovement + sprite.collisionOffset; |
63 | vec2i newColDR = newColUL + sprite.collisionSize; | 66 | vec2i newColDR = newColUL + sprite.collisionSize; |
64 | 67 | ||
65 | vec2i oldTileUL = oldColUL / map.getTileSize(); | 68 | vec2i oldTileUL = oldColUL / map.getTileSize(); |
@@ -154,6 +157,26 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i curLoc, vec2 | |||
154 | } | 157 | } |
155 | } | 158 | } |
156 | 159 | ||
160 | // For vertical movement, assume that the horizontal movement has already | ||
161 | // taken place (as long as it was not in fact blocked). | ||
162 | vec2i effectiveCurLoc = curLoc; | ||
163 | vec2i vertMovement = newLoc; | ||
164 | if (result.horiz.blocked) { | ||
165 | vertMovement.x() = curLoc.x(); | ||
166 | } else { | ||
167 | effectiveCurLoc.x() = newLoc.x(); | ||
168 | } | ||
169 | |||
170 | oldColUL = effectiveCurLoc + sprite.collisionOffset; | ||
171 | oldColDR = oldColUL + sprite.collisionSize; | ||
172 | newColUL = vertMovement + sprite.collisionOffset; | ||
173 | newColDR = newColUL + sprite.collisionSize; | ||
174 | |||
175 | oldTileUL = oldColUL / map.getTileSize(); | ||
176 | newTileUL = newColUL / map.getTileSize(); | ||
177 | oldTileDR = oldColDR / map.getTileSize(); | ||
178 | newTileDR = newColDR / map.getTileSize(); | ||
179 | |||
157 | if (dirHasDir(dir, Direction::down)) { | 180 | if (dirHasDir(dir, Direction::down)) { |
158 | if (newTileDR.y() > oldTileDR.y() && | 181 | if (newTileDR.y() > oldTileDR.y() && |
159 | newColDR.y() < mapBounds.h()) { | 182 | newColDR.y() < mapBounds.h()) { |