summary refs log tree commit diff stats
path: root/src/systems/orienting.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-12-20 18:57:23 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-12-20 18:57:23 -0500
commit62069b31c7d23055f999c70a58ccf7d58acd333f (patch)
tree7ea4c57e74d978a297d34cf61d9c85db846e8900 /src/systems/orienting.cpp
parent90aadf3844386824140a20d7fbb847bc16009a94 (diff)
downloadtherapy-master.tar.gz
therapy-master.tar.bz2
therapy-master.zip
Added target velocity HEAD master
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.
Diffstat (limited to 'src/systems/orienting.cpp')
-rw-r--r--src/systems/orienting.cpp32
1 files changed, 8 insertions, 24 deletions
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)
20 auto& ponderable = game_.getEntityManager(). 20 auto& ponderable = game_.getEntityManager().
21 getComponent<PonderableComponent>(entity); 21 getComponent<PonderableComponent>(entity);
22 22
23 switch (orientable.getWalkState())
24 {
25 case OrientableComponent::WalkState::still:
26 {
27 ponderable.vel.x() = 0.0;
28
29 break;
30 }
31
32 case OrientableComponent::WalkState::left:
33 {
34 ponderable.vel.x() = -WALK_SPEED;
35
36 break;
37 }
38
39 case OrientableComponent::WalkState::right:
40 {
41 ponderable.vel.x() = WALK_SPEED;
42
43 break;
44 }
45 }
46
47 if (orientable.isJumping() && (ponderable.vel.y() > 0)) 23 if (orientable.isJumping() && (ponderable.vel.y() > 0))
48 { 24 {
49 orientable.setJumping(false); 25 orientable.setJumping(false);
@@ -62,6 +38,8 @@ void OrientingSystem::moveLeft(id_type entity)
62 orientable.setFacingRight(false); 38 orientable.setFacingRight(false);
63 orientable.setWalkState(OrientableComponent::WalkState::left); 39 orientable.setWalkState(OrientableComponent::WalkState::left);
64 40
41 ponderable.targetVel.x() = -WALK_SPEED;
42
65 auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); 43 auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>();
66 if (ponderable.grounded) 44 if (ponderable.grounded)
67 { 45 {
@@ -82,6 +60,8 @@ void OrientingSystem::moveRight(id_type entity)
82 orientable.setFacingRight(true); 60 orientable.setFacingRight(true);
83 orientable.setWalkState(OrientableComponent::WalkState::right); 61 orientable.setWalkState(OrientableComponent::WalkState::right);
84 62
63 ponderable.targetVel.x() = WALK_SPEED;
64
85 auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); 65 auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>();
86 if (ponderable.grounded) 66 if (ponderable.grounded)
87 { 67 {
@@ -93,10 +73,14 @@ void OrientingSystem::moveRight(id_type entity)
93 73
94void OrientingSystem::stopWalking(id_type entity) 74void OrientingSystem::stopWalking(id_type entity)
95{ 75{
76 auto& ponderable = game_.getEntityManager().
77 getComponent<PonderableComponent>(entity);
78
96 auto& orientable = game_.getEntityManager(). 79 auto& orientable = game_.getEntityManager().
97 getComponent<OrientableComponent>(entity); 80 getComponent<OrientableComponent>(entity);
98 81
99 orientable.setWalkState(OrientableComponent::WalkState::still); 82 orientable.setWalkState(OrientableComponent::WalkState::still);
83 ponderable.targetVel.x() = 0;
100 84
101 auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); 85 auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>();
102 86