mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 07:53:43 +00:00
Hotfix collision to the right
breaks sliding
This commit is contained in:
parent
0c1c9a7f84
commit
f538e95623
@ -8,6 +8,7 @@
|
||||
|
||||
#include <SDL_rect.h>
|
||||
#include <bitset>
|
||||
#include <cstdio>
|
||||
|
||||
IntersectionBitSet CollisionHandler::getIntersection(Entity* entityA, Entity* entityB)
|
||||
{
|
||||
@ -31,17 +32,25 @@ IntersectionBitSet CollisionHandler::getIntersection(Entity* entityA, Entity* en
|
||||
std::bitset<DIRECTION_C> intersections;
|
||||
|
||||
// checks all 4 directions to allow checking full overlap
|
||||
if (colliderA->x + posModA.x < colliderB->x + colliderB->w + posModB.x)
|
||||
intersections.set((size_t) direction::LEFT) = 1;
|
||||
if (colliderA->x + posModA.x < colliderB->x + colliderB->w + posModB.x &&
|
||||
colliderA->x + posModA.x > colliderB->x + posModB.x) {
|
||||
printf("%zu left\n", (size_t) direction::LEFT);
|
||||
intersections.set((size_t) direction::LEFT);
|
||||
}
|
||||
|
||||
if (colliderA->x + colliderA->w + posModA.x > colliderB->x + posModB.x)
|
||||
intersections.set((size_t) direction::RIGHT) = 1;
|
||||
if (colliderA->x + colliderA->w + posModA.x < colliderB->x + colliderB->w + posModB.x &&
|
||||
colliderA->x + colliderA->w + posModA.x > colliderB->x + posModB.x) {
|
||||
printf("%zu right\n", (size_t) direction::RIGHT);
|
||||
intersections.set((size_t) direction::RIGHT);
|
||||
}
|
||||
|
||||
if (colliderA->y + posModA.y < colliderB->y + colliderB->h + posModB.y)
|
||||
intersections.set((size_t) direction::UP) = 1;
|
||||
if (colliderA->y + posModA.y < colliderB->y + colliderB->h + posModB.y &&
|
||||
colliderA->y + posModA.y > colliderB->y + posModB.y)
|
||||
intersections.set((size_t) direction::UP);
|
||||
|
||||
if (colliderA->y + colliderA->h + posModA.y > colliderB->y + posModB.y)
|
||||
intersections.set((size_t) direction::DOWN) = 1;
|
||||
if (colliderA->y + colliderA->h + posModA.y < colliderB->y + colliderB->h + posModB.y &&
|
||||
colliderA->y + colliderA->h + posModA.y > colliderB->y + posModB.y)
|
||||
intersections.set((size_t) direction::DOWN);
|
||||
|
||||
return intersections;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user