mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 07:53:43 +00:00
Merged duplicate Direction enums
This commit is contained in:
parent
b2a001e24d
commit
680f66270f
@ -19,14 +19,6 @@ class Entity;
|
||||
|
||||
constexpr uint8_t DIRECTION_C = 4;
|
||||
|
||||
enum class direction
|
||||
{
|
||||
LEFT = 0,
|
||||
RIGHT,
|
||||
UP,
|
||||
DOWN
|
||||
};
|
||||
|
||||
using IntersectionBitSet = std::bitset<DIRECTION_C>;
|
||||
|
||||
class CollisionHandler
|
||||
|
||||
@ -3,5 +3,7 @@
|
||||
enum class Direction
|
||||
{
|
||||
LEFT,
|
||||
RIGHT
|
||||
RIGHT,
|
||||
UP,
|
||||
DOWN
|
||||
};
|
||||
@ -36,21 +36,21 @@ IntersectionBitSet CollisionHandler::getIntersection(Entity* entityA, Entity* en
|
||||
// checks all 4 directions to allow checking full overlap
|
||||
if (colliderA.x < colliderB.x + colliderB.w &&
|
||||
colliderA.x > colliderB.x) {
|
||||
intersections.set((size_t) direction::LEFT);
|
||||
intersections.set((size_t) Direction::LEFT);
|
||||
}
|
||||
|
||||
if (colliderA.x + colliderA.w < colliderB.x + colliderB.w &&
|
||||
colliderA.x + colliderA.w > colliderB.x) {
|
||||
intersections.set((size_t) direction::RIGHT);
|
||||
intersections.set((size_t) Direction::RIGHT);
|
||||
}
|
||||
|
||||
if (colliderA.y < colliderB.y + colliderB.h &&
|
||||
colliderA.y > colliderB.y)
|
||||
intersections.set((size_t) direction::UP);
|
||||
intersections.set((size_t) Direction::UP);
|
||||
|
||||
if (colliderA.y + colliderA.h < colliderB.y + colliderB.h &&
|
||||
colliderA.y + colliderA.h > colliderB.y)
|
||||
intersections.set((size_t) direction::DOWN);
|
||||
intersections.set((size_t) Direction::DOWN);
|
||||
|
||||
return intersections;
|
||||
}
|
||||
@ -67,20 +67,20 @@ IntersectionBitSet CollisionHandler::getIntersectionWithBounds(Entity* entity, V
|
||||
// all 4 directions and both sides to allow checking for fully out of bounds
|
||||
if (collider->x + posMod.x < 0 ||
|
||||
collider->x + posMod.x > SCREEN_SIZE_WIDTH) {
|
||||
intersections.set((size_t) direction::LEFT);
|
||||
intersections.set((size_t) Direction::LEFT);
|
||||
}
|
||||
|
||||
if (collider->x + collider->w + posMod.x < 0 ||
|
||||
collider->x + collider->w + posMod.x > SCREEN_SIZE_WIDTH)
|
||||
intersections.set((size_t) direction::RIGHT);
|
||||
intersections.set((size_t) Direction::RIGHT);
|
||||
|
||||
if (collider->y + posMod.y < 0 ||
|
||||
collider->y + posMod.y > SCREEN_SIZE_HEIGHT)
|
||||
intersections.set((size_t) direction::UP);
|
||||
intersections.set((size_t) Direction::UP);
|
||||
|
||||
if (collider->y + collider->h + posMod.y < 0 ||
|
||||
collider->y + collider->h + posMod.y > SCREEN_SIZE_HEIGHT)
|
||||
intersections.set((size_t) direction::DOWN);
|
||||
intersections.set((size_t) Direction::DOWN);
|
||||
|
||||
return intersections;
|
||||
}
|
||||
|
||||
@ -71,10 +71,10 @@ void TransformComponent::update()
|
||||
(Game::collisionHandler->getAnyIntersection<IntersectionBitSet>(entity, Vector2D(0, positionChange.y), { GroupLabel::MAPTILES, GroupLabel::COLLIDERS })) &
|
||||
IntersectionBitSet("1100"));
|
||||
|
||||
if (intersections.test((size_t)direction::LEFT) || intersections.test((size_t)direction::RIGHT))
|
||||
if (intersections.test((size_t)Direction::LEFT) || intersections.test((size_t)Direction::RIGHT))
|
||||
positionChange.x = 0;
|
||||
|
||||
if (intersections.test((size_t)direction::UP) || intersections.test((size_t)direction::DOWN))
|
||||
if (intersections.test((size_t)Direction::UP) || intersections.test((size_t)Direction::DOWN))
|
||||
positionChange.y = 0;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user