0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 13:43:41 +00:00

Merged duplicate Direction enums

This commit is contained in:
Benedikt Galbavy 2024-02-02 15:10:38 +01:00
parent b2a001e24d
commit 680f66270f
4 changed files with 13 additions and 19 deletions

View File

@ -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

View File

@ -3,5 +3,7 @@
enum class Direction
{
LEFT,
RIGHT
RIGHT,
UP,
DOWN
};

View File

@ -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;
}

View File

@ -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;
}