summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-22 22:40:03 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-22 22:40:03 -0500
commit96e93ae852f79346f71c1b94f704b7f8e986f251 (patch)
treedb27ec59e7d0f7ab3d3f3c211e67b9af41318982
parent09133930d96ec1b9dc398cda59376622b7d5177f (diff)
downloadtanetane-96e93ae852f79346f71c1b94f704b7f8e986f251.tar.gz
tanetane-96e93ae852f79346f71c1b94f704b7f8e986f251.tar.bz2
tanetane-96e93ae852f79346f71c1b94f704b7f8e986f251.zip
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).
-rw-r--r--src/transform_system.cpp8
1 files changed, 4 insertions, 4 deletions
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
94 } 94 }
95 95
96 if (!result.horiz.blocked) { 96 if (!result.horiz.blocked) {
97 auto it = rightCollidables_.lower_bound({oldColDR.x(), INT_MAX}); 97 auto it = rightCollidables_.lower_bound({oldColDR.x()+1, 0});
98 for (; 98 for (;
99 (it != std::end(rightCollidables_) && 99 (it != std::end(rightCollidables_) &&
100 std::get<0>(it->first) <= newColDR.x()); 100 std::get<0>(it->first) <= newColDR.x());
@@ -135,7 +135,7 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
135 } 135 }
136 136
137 if (!result.horiz.blocked) { 137 if (!result.horiz.blocked) {
138 auto it = leftCollidables_.lower_bound({oldColUL.x(), 0}); 138 auto it = leftCollidables_.lower_bound({oldColUL.x()-1, INT_MAX});
139 for (; 139 for (;
140 (it != std::end(leftCollidables_) && 140 (it != std::end(leftCollidables_) &&
141 std::get<0>(it->first) >= newColUL.x()); 141 std::get<0>(it->first) >= newColUL.x());
@@ -176,7 +176,7 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
176 } 176 }
177 177
178 if (!result.vert.blocked) { 178 if (!result.vert.blocked) {
179 auto it = downCollidables_.lower_bound({oldColDR.y(), INT_MAX}); 179 auto it = downCollidables_.lower_bound({oldColDR.y()+1, 0});
180 for (; 180 for (;
181 (it != std::end(downCollidables_) && 181 (it != std::end(downCollidables_) &&
182 std::get<0>(it->first) <= newColDR.y()); 182 std::get<0>(it->first) <= newColDR.y());
@@ -217,7 +217,7 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
217 } 217 }
218 218
219 if (!result.vert.blocked) { 219 if (!result.vert.blocked) {
220 auto it = upCollidables_.lower_bound({oldColUL.y(), 0}); 220 auto it = upCollidables_.lower_bound({oldColUL.y()-1, INT_MAX});
221 for (; 221 for (;
222 (it != std::end(upCollidables_) && 222 (it != std::end(upCollidables_) &&
223 std::get<0>(it->first) >= newColUL.y()); 223 std::get<0>(it->first) >= newColUL.y());