diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index daab3de5..acc5b671 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -282,7 +282,7 @@ namespace BBM { double rnd = static_cast(std::rand()) / RAND_MAX; - if (rnd > 0.60) { + if (rnd > 0.01) { for (int i = 0; i < width + 1; i++) { map[std::make_tuple(i, 1, height)] = map[std::make_tuple(i, 0, height)]; map[std::make_tuple(i, 0, height)] = UPPERFLOOR; @@ -295,12 +295,10 @@ namespace BBM map[std::make_tuple(width, -1, 1)] = BUMPER; map[std::make_tuple(width / 2, -1, height - 1)] = BUMPER; map[std::make_tuple(width / 2, -1, 1)] = BUMPER; - } - if (rnd > 0.30) { + } + if (rnd > 0.01) { for (int i = width / 2 - width / 4; i < width / 2 + width / 4 + 1; i++) { for (int j = height / 2 - height / 4; j < height / 2 + height / 4 + 1; j++) { - if (map[std::make_tuple(i, 0, j)] == FLOOR) - continue; map[std::make_tuple(i, 1, j)] = map[std::make_tuple(i, 0, j)]; map[std::make_tuple(i, 0, j)] = UPPERFLOOR; } diff --git a/sources/System/Collision/CollisionSystem.cpp b/sources/System/Collision/CollisionSystem.cpp index db68e3c0..ce924797 100644 --- a/sources/System/Collision/CollisionSystem.cpp +++ b/sources/System/Collision/CollisionSystem.cpp @@ -31,23 +31,30 @@ namespace BBM Vector3f pointAx = pointA; Vector3f pointAy = pointA; Vector3f pointAz = pointA; + bool isMovable = false; + Vector3f minAy; + Vector3f maxAy; + Vector3f minAz; + Vector3f maxAz; if (auto *movable = entity->tryGetComponent()) { auto vel = movable->getVelocity(); pointAx.x += vel.x; pointAy.y += vel.y; pointAz.z += vel.z; + isMovable = true; } Vector3f minAx = Vector3f::min(pointAx, pointAx + colA.bound); Vector3f maxAx = Vector3f::max(pointAx, pointAx + colA.bound); - Vector3f minAy = Vector3f::min(pointAy, pointAy + colA.bound); - Vector3f maxAy = Vector3f::max(pointAy, pointAy + colA.bound); - - Vector3f minAz = Vector3f::min(pointAz, pointAz + colA.bound); - Vector3f maxAz = Vector3f::max(pointAz, pointAz + colA.bound); + if (isMovable) { + minAy = Vector3f::min(pointAy, pointAy + colA.bound); + maxAy = Vector3f::max(pointAy, pointAy + colA.bound); + minAz = Vector3f::min(pointAz, pointAz + colA.bound); + maxAz = Vector3f::max(pointAz, pointAz + colA.bound); + } for (auto &[other, posB, colB] : this->getView()) { if (other.getUid() == entity->getUid()) continue; @@ -60,13 +67,15 @@ namespace BBM Vector3f maxB = Vector3f::max(pointB, pointB + colB.bound); if (boxesCollide(minAx, maxAx, minB, maxB)) { - collidedAxis += CollisionComponent::CollidedAxis::X; + collidedAxis += isMovable ? CollisionComponent::CollidedAxis::X : 7; } - if (boxesCollide(minAy, maxAy, minB, maxB)) { - collidedAxis += CollisionComponent::CollidedAxis::Y; - } - if (boxesCollide(minAz, maxAz, minB, maxB)) { - collidedAxis += CollisionComponent::CollidedAxis::Z; + if (isMovable) { + if (boxesCollide(minAy, maxAy, minB, maxB)) { + collidedAxis += CollisionComponent::CollidedAxis::Y; + } + if (boxesCollide(minAz, maxAz, minB, maxB)) { + collidedAxis += CollisionComponent::CollidedAxis::Z; + } } if (collidedAxis) { colA.onCollide(entity, other, static_cast(collidedAxis));