From 83534176373bd05a13db88ffff095f52cca07a21 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 4 May 2018 11:08:48 -0400 Subject: Fixed behavior of frozen bodies Frozen bodies are now still ticked, but their velocities and positions are no longer changed. This change was made so that frozen bodies can still be ungrounded/unferried, and that passengers of frozen bodies can still be ticked. Also fixes a compile error. --- src/components/ponderable.h | 5 ++++- src/systems/pondering.cpp | 50 ++++++++++++++++++++++++++------------------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/components/ponderable.h b/src/components/ponderable.h index 45150a0..6a01400 100644 --- a/src/components/ponderable.h +++ b/src/components/ponderable.h @@ -100,7 +100,10 @@ public: std::set passengers; /** - * If enabled, this will prevent the body from moving. + * If enabled, this will prevent the body from moving and accelerating. The + * velocity and position of the body can still be affected by sources external + * to the PonderingSystem. Enabling this will cause applicable bodies to + * become ungrounded and unferried. */ bool frozen = false; diff --git a/src/systems/pondering.cpp b/src/systems/pondering.cpp index e6417eb..0be3add 100644 --- a/src/systems/pondering.cpp +++ b/src/systems/pondering.cpp @@ -91,9 +91,9 @@ void PonderingSystem::tickBody( auto& ponderable = game_.getEntityManager(). getComponent(entity); - if (!ponderable.active || ponderable.frozen) + if (!ponderable.active) { - continue; + return; } auto& realizable = game_.getEntityManager(). @@ -109,13 +109,16 @@ void PonderingSystem::tickBody( getComponent(entity); // Accelerate - ponderable.velX += ponderable.accelX * dt; - ponderable.velY += ponderable.accelY * dt; - - if ((ponderable.type == PonderableComponent::Type::freefalling) - && (ponderable.velY > TERMINAL_VELOCITY)) + if (!ponderable.frozen) { - ponderable.velY = TERMINAL_VELOCITY; + ponderable.velX += ponderable.accelX * dt; + ponderable.velY += ponderable.accelY * dt; + + if ((ponderable.type == PonderableComponent::Type::freefalling) + && (ponderable.velY > TERMINAL_VELOCITY)) + { + ponderable.velY = TERMINAL_VELOCITY; + } } const double oldX = transformable.x; @@ -124,21 +127,23 @@ void PonderingSystem::tickBody( const double oldBottom = oldY + transformable.h; CollisionResult result; + result.newX = transformable.x; + result.newY = transformable.y; - if (ponderable.ferried) + if (!ponderable.frozen) { - auto& ferryTrans = game_.getEntityManager(). - getComponent(ponderable.ferry); + if (ponderable.ferried) + { + auto& ferryTrans = game_.getEntityManager(). + getComponent(ponderable.ferry); - result.newX = ferryTrans.x + ponderable.relX; - result.newY = ferryTrans.y + ponderable.relY; - } else { - result.newX = transformable.x; - result.newY = transformable.y; - } + result.newX = ferryTrans.x + ponderable.relX; + result.newY = ferryTrans.y + ponderable.relY; + } - result.newX += ponderable.velX * dt; - result.newY += ponderable.velY * dt; + result.newX += ponderable.velX * dt; + result.newY += ponderable.velY * dt; + } bool oldGrounded = ponderable.grounded; ponderable.grounded = false; @@ -694,8 +699,11 @@ void PonderingSystem::tickBody( } // Move - transformable.x = result.newX; - transformable.y = result.newY; + if (!ponderable.frozen) + { + transformable.x = result.newX; + transformable.y = result.newY; + } // Perform cleanup for orientable entites if (game_.getEntityManager().hasComponent(entity)) -- cgit 1.4.1