From 96e93ae852f79346f71c1b94f704b7f8e986f251 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 22 Feb 2021 22:40:03 -0500 Subject: Fixed issue with double counting collisions Because of an issue with how collision checking with sprites worked, it was possible that you could collide with a boundary twice (once when moving up to it, and once when moving from it to past it, instead of just one or the other) when moving up or left as long as the colliding sprite had the ID zero. This was causing a fun issue where the map change script from hallucination_interior to hallucination_cliff was getting triggered twice, but only every other time. Because we're using integers and not real numbers, we can make the boundary exclusive by adding one. The issue was also technically possible in the down and right directions, but only if the sprite ID was INT_MAX, which is unlikely to occur. It was decided that the former collision is the real one (if you start away from the boundary and then move into it). --- src/transform_system.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/transform_system.cpp') diff --git a/src/transform_system.cpp b/src/transform_system.cpp index b5e9b7c..ee392f1 100644 --- a/src/transform_system.cpp +++ b/src/transform_system.cpp @@ -94,7 +94,7 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire } if (!result.horiz.blocked) { - auto it = rightCollidables_.lower_bound({oldColDR.x(), INT_MAX}); + auto it = rightCollidables_.lower_bound({oldColDR.x()+1, 0}); for (; (it != std::end(rightCollidables_) && std::get<0>(it->first) <= newColDR.x()); @@ -135,7 +135,7 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire } if (!result.horiz.blocked) { - auto it = leftCollidables_.lower_bound({oldColUL.x(), 0}); + auto it = leftCollidables_.lower_bound({oldColUL.x()-1, INT_MAX}); for (; (it != std::end(leftCollidables_) && std::get<0>(it->first) >= newColUL.x()); @@ -176,7 +176,7 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire } if (!result.vert.blocked) { - auto it = downCollidables_.lower_bound({oldColDR.y(), INT_MAX}); + auto it = downCollidables_.lower_bound({oldColDR.y()+1, 0}); for (; (it != std::end(downCollidables_) && std::get<0>(it->first) <= newColDR.y()); @@ -217,7 +217,7 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire } if (!result.vert.blocked) { - auto it = upCollidables_.lower_bound({oldColUL.y(), 0}); + auto it = upCollidables_.lower_bound({oldColUL.y()-1, INT_MAX}); for (; (it != std::end(upCollidables_) && std::get<0>(it->first) >= newColUL.y()); -- cgit 1.4.1