From 62069b31c7d23055f999c70a58ccf7d58acd333f Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 20 Dec 2018 18:57:23 -0500 Subject: Added target velocity The acceleration of a Ponderable entity is now only really a magnitude. The direction of acceleration is such that the velocity goes toward the target velocity. If accelerating would cause the velocity to pass the target velocity, it is instead set to the target. This is currently being used to 1) generalize terminal velocity due to gravity, and 2) allow an Orientable entity to accelerate quickly to a walking speed (and to a halt) rather than instantly achieve it. --- src/systems/orienting.cpp | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) (limited to 'src/systems/orienting.cpp') diff --git a/src/systems/orienting.cpp b/src/systems/orienting.cpp index d73ddd2..a2be34f 100644 --- a/src/systems/orienting.cpp +++ b/src/systems/orienting.cpp @@ -20,30 +20,6 @@ void OrientingSystem::tick(double) auto& ponderable = game_.getEntityManager(). getComponent(entity); - switch (orientable.getWalkState()) - { - case OrientableComponent::WalkState::still: - { - ponderable.vel.x() = 0.0; - - break; - } - - case OrientableComponent::WalkState::left: - { - ponderable.vel.x() = -WALK_SPEED; - - break; - } - - case OrientableComponent::WalkState::right: - { - ponderable.vel.x() = WALK_SPEED; - - break; - } - } - if (orientable.isJumping() && (ponderable.vel.y() > 0)) { orientable.setJumping(false); @@ -62,6 +38,8 @@ void OrientingSystem::moveLeft(id_type entity) orientable.setFacingRight(false); orientable.setWalkState(OrientableComponent::WalkState::left); + ponderable.targetVel.x() = -WALK_SPEED; + auto& animating = game_.getSystemManager().getSystem(); if (ponderable.grounded) { @@ -82,6 +60,8 @@ void OrientingSystem::moveRight(id_type entity) orientable.setFacingRight(true); orientable.setWalkState(OrientableComponent::WalkState::right); + ponderable.targetVel.x() = WALK_SPEED; + auto& animating = game_.getSystemManager().getSystem(); if (ponderable.grounded) { @@ -93,10 +73,14 @@ void OrientingSystem::moveRight(id_type entity) void OrientingSystem::stopWalking(id_type entity) { + auto& ponderable = game_.getEntityManager(). + getComponent(entity); + auto& orientable = game_.getEntityManager(). getComponent(entity); orientable.setWalkState(OrientableComponent::WalkState::still); + ponderable.targetVel.x() = 0; auto& animating = game_.getSystemManager().getSystem(); -- cgit 1.4.1