summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-05-04 00:08:35 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-05-09 17:59:13 -0400
commit69c04dfb6c49e7b2d34a6699c071f037880fbde5 (patch)
tree2cab984cb5723dfdda00bd2f4062ebaac0222be1 /src
parent83f51a6892629921b4cc482b986656a0a5cc5f6a (diff)
downloadtherapy-69c04dfb6c49e7b2d34a6699c071f037880fbde5.tar.gz
therapy-69c04dfb6c49e7b2d34a6699c071f037880fbde5.tar.bz2
therapy-69c04dfb6c49e7b2d34a6699c071f037880fbde5.zip
Added ferrying (buggy)
A freefalling body is considered to be "ferried" if it is grounded by another body (not a map). Its location is then dependent on the ferry's location; in this way, the ferry carries the passenger around.

This implementation is kind of buggy currently: first of all, ferrying does not work vertically upward, because the ferry will consider the passenger to be a wall and will not continue moving upward.

Second, ferries are not processed before passengers, so passengers can move in a physics tick using the knowledge of a ferry's location before it moves in that tick.

Third, if the transform coordinates are set by any system other than the PonderingSystem, the relative coordinates to the ferry will not be updated and the body will not be unferried if necessary.

This is still a cool commit because, three years later, we have finally overcome the issue that stopped development on the original branch in 2015.
Diffstat (limited to 'src')
-rw-r--r--src/components/ponderable.h33
-rw-r--r--src/systems/pondering.cpp57
-rw-r--r--src/systems/pondering.h1
3 files changed, 89 insertions, 2 deletions
diff --git a/src/components/ponderable.h b/src/components/ponderable.h index 5354f87..45150a0 100644 --- a/src/components/ponderable.h +++ b/src/components/ponderable.h
@@ -1,11 +1,15 @@
1#ifndef TANGIBLE_H_746DB3EE 1#ifndef TANGIBLE_H_746DB3EE
2#define TANGIBLE_H_746DB3EE 2#define TANGIBLE_H_746DB3EE
3 3
4#include <set>
4#include "component.h" 5#include "component.h"
6#include "entity_manager.h"
5 7
6class PonderableComponent : public Component { 8class PonderableComponent : public Component {
7public: 9public:
8 10
11 using id_type = EntityManager::id_type;
12
9 /** 13 /**
10 * List of different types of physical bodies. 14 * List of different types of physical bodies.
11 * 15 *
@@ -67,6 +71,35 @@ public:
67 bool grounded = false; 71 bool grounded = false;
68 72
69 /** 73 /**
74 * Whether or not a freefalling body is being ferried by another body.
75 *
76 * @managed_by PonderingSystem
77 */
78 bool ferried = false;
79
80 /**
81 * The entity that is ferrying this body, if there is one.
82 *
83 * @managed_by PonderingSystem
84 */
85 id_type ferry;
86
87 /**
88 * The location of the body relative to the location of its ferry.
89 *
90 * @managed_by PonderingSystem
91 */
92 double relX;
93 double relY;
94
95 /**
96 * The bodies that are being ferried by this body.
97 *
98 * @managed_by PonderingSystem
99 */
100 std::set<id_type> passengers;
101
102 /**
70 * If enabled, this will prevent the body from moving. 103 * If enabled, this will prevent the body from moving.
71 */ 104 */
72 bool frozen = false; 105 bool frozen = false;
diff --git a/src/systems/pondering.cpp b/src/systems/pondering.cpp index 5143f8e..ccfd66f 100644 --- a/src/systems/pondering.cpp +++ b/src/systems/pondering.cpp
@@ -57,8 +57,21 @@ void PonderingSystem::tick(double dt)
57 const double oldBottom = oldY + transformable.h; 57 const double oldBottom = oldY + transformable.h;
58 58
59 CollisionResult result; 59 CollisionResult result;
60 result.newX = oldX + ponderable.velX * dt; 60
61 result.newY = oldY + ponderable.velY * dt; 61 if (ponderable.ferried)
62 {
63 auto& ferryTrans = game_.getEntityManager().
64 getComponent<TransformableComponent>(ponderable.ferry);
65
66 result.newX = ferryTrans.x + ponderable.relX;
67 result.newY = ferryTrans.y + ponderable.relY;
68 } else {
69 result.newX = transformable.x;
70 result.newY = transformable.y;
71 }
72
73 result.newX += ponderable.velX * dt;
74 result.newY += ponderable.velY * dt;
62 75
63 bool oldGrounded = ponderable.grounded; 76 bool oldGrounded = ponderable.grounded;
64 ponderable.grounded = false; 77 ponderable.grounded = false;
@@ -642,6 +655,43 @@ void PonderingSystem::tick(double dt)
642 } 655 }
643 } 656 }
644 657
658 // Handle ferry passengers
659 if ((ponderable.type == PonderableComponent::Type::freefalling) &&
660 (ponderable.grounded != oldGrounded))
661 {
662 if (ponderable.grounded &&
663 game_.getEntityManager().
664 hasComponent<PonderableComponent>(result.groundEntity))
665 {
666 // The body is now being ferried
667 auto& ferryPonder = game_.getEntityManager().
668 getComponent<PonderableComponent>(result.groundEntity);
669
670 ponderable.ferried = true;
671 ponderable.ferry = result.groundEntity;
672
673 ferryPonder.passengers.insert(entity);
674 } else if (ponderable.ferried)
675 {
676 // The body is no longer being ferried
677 ponderable.ferried = false;
678
679 auto& ferryPonder = game_.getEntityManager().
680 getComponent<PonderableComponent>(ponderable.ferry);
681
682 ferryPonder.passengers.erase(entity);
683 }
684 }
685
686 if (ponderable.ferried)
687 {
688 auto& ferryTrans = game_.getEntityManager().
689 getComponent<TransformableComponent>(ponderable.ferry);
690
691 ponderable.relX = transformable.x - ferryTrans.x;
692 ponderable.relY = transformable.y - ferryTrans.y;
693 }
694
645 // Move to an adjacent map, if necessary 695 // Move to an adjacent map, if necessary
646 if (result.adjacentlyWarping) 696 if (result.adjacentlyWarping)
647 { 697 {
@@ -714,6 +764,8 @@ void PonderingSystem::initPrototype(id_type prototype)
714 ponderable.grounded = false; 764 ponderable.grounded = false;
715 ponderable.frozen = false; 765 ponderable.frozen = false;
716 ponderable.collidable = true; 766 ponderable.collidable = true;
767 ponderable.ferried = false;
768 ponderable.passengers.clear();
717} 769}
718 770
719void PonderingSystem::processCollision( 771void PonderingSystem::processCollision(
@@ -900,6 +952,7 @@ void PonderingSystem::processCollision(
900 case Direction::down: 952 case Direction::down:
901 { 953 {
902 result.newY = axis - transformable.h; 954 result.newY = axis - transformable.h;
955 result.groundEntity = collider;
903 ponderable.velY = 0.0; 956 ponderable.velY = 0.0;
904 ponderable.grounded = true; 957 ponderable.grounded = true;
905 958
diff --git a/src/systems/pondering.h b/src/systems/pondering.h index aa430db..b195814 100644 --- a/src/systems/pondering.h +++ b/src/systems/pondering.h
@@ -29,6 +29,7 @@ private:
29 bool adjacentlyWarping = false; 29 bool adjacentlyWarping = false;
30 Direction adjWarpDir; 30 Direction adjWarpDir;
31 size_t adjWarpMapId; 31 size_t adjWarpMapId;
32 id_type groundEntity;
32 }; 33 };
33 34
34 void processCollision( 35 void processCollision(