From 5cc80ec58ea5bd66456f6f5286fa5f26d3fe702b Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 12 Feb 2018 16:39:49 -0500 Subject: Abstracted behavior related to "orientable" entities A lot of the stuff that ControllingSystem did to control the player character was moved into the new OrientingSystem. This is so that the player, or any player-like entities, can also be controlled by AI, with the underlying behavior being delegated in the same way as if the player were being controlled by the user. Fixed the issue where, if the player were blocked while moving horizontally, they would remain blocked even if vertical movement were to remove the collision. Fixed cases of the player animating incorrectly after performing certain movements. --- src/systems/pondering.cpp | 89 +++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 41 deletions(-) (limited to 'src/systems/pondering.cpp') diff --git a/src/systems/pondering.cpp b/src/systems/pondering.cpp index 26a6f56..4a165b1 100644 --- a/src/systems/pondering.cpp +++ b/src/systems/pondering.cpp @@ -2,7 +2,9 @@ #include "game.h" #include "components/ponderable.h" #include "components/transformable.h" -#include "components/droppable.h" +#include "components/orientable.h" +#include "components/mappable.h" +#include "systems/orienting.h" #include "consts.h" void PonderingSystem::tick(double dt) @@ -37,10 +39,8 @@ void PonderingSystem::tick(double dt) double newX = oldX + ponderable.getVelocityX() * dt; double newY = oldY + ponderable.getVelocityY() * dt; - if (ponderable.getVelocityY() > 0.0) - { - ponderable.setState(PonderableComponent::State::falling); - } + bool oldGrounded = ponderable.isGrounded(); + ponderable.setGrounded(false); for (id_type mapEntity : maps) { @@ -64,8 +64,6 @@ void PonderingSystem::tick(double dt) newY, it->first, it->second.getType()); - - break; } } } else if (newX > oldX) @@ -86,8 +84,6 @@ void PonderingSystem::tick(double dt) newY, it->first, it->second.getType()); - - break; } } } @@ -109,8 +105,6 @@ void PonderingSystem::tick(double dt) newY, it->first, it->second.getType()); - - break; } } } else if (newY > oldY) @@ -131,8 +125,6 @@ void PonderingSystem::tick(double dt) newY, it->first, it->second.getType()); - - break; } } } @@ -141,6 +133,31 @@ void PonderingSystem::tick(double dt) // Move transformable.setX(newX); transformable.setY(newY); + + // Perform cleanup for orientable entites + if (game_.getEntityManager().hasComponent(entity)) + { + auto& orientable = game_.getEntityManager(). + getComponent(entity); + + // Handle changes in groundedness + if (ponderable.isGrounded() != oldGrounded) + { + if (ponderable.isGrounded()) + { + game_.getSystemManager().getSystem().land(entity); + } else { + game_.getSystemManager(). + getSystem().startFalling(entity); + } + } + + // Complete dropping, if necessary + if (orientable.getDropState() == OrientableComponent::DropState::active) + { + orientable.setDropState(OrientableComponent::DropState::none); + } + } } } @@ -153,8 +170,7 @@ void PonderingSystem::initializeBody( if (type == PonderableComponent::Type::freefalling) { - ponderable.setAccelY(JUMP_GRAVITY(TILE_HEIGHT*3.5, 0.233)); - ponderable.setState(PonderableComponent::State::falling); + ponderable.setAccelY(NORMAL_GRAVITY); } } @@ -172,6 +188,8 @@ void PonderingSystem::processCollision( auto& transformable = game_.getEntityManager(). getComponent(entity); + bool touchedGround = false; + switch (type) { case MappableComponent::Boundary::Type::wall: @@ -204,13 +222,7 @@ void PonderingSystem::processCollision( case Direction::down: { - newY = axis - transformable.getH(); - ponderable.setVelocityY(0.0); - - if (ponderable.getState() == PonderableComponent::State::falling) - { - ponderable.setState(PonderableComponent::State::grounded); - } + touchedGround = true; break; } @@ -221,31 +233,19 @@ void PonderingSystem::processCollision( case MappableComponent::Boundary::Type::platform: { - if (game_.getEntityManager().hasComponent(entity)) + if (game_.getEntityManager().hasComponent(entity)) { - auto& droppable = game_.getEntityManager(). - getComponent(entity); + auto& orientable = game_.getEntityManager(). + getComponent(entity); - if (droppable.isDroppable()) + if (orientable.getDropState() != OrientableComponent::DropState::none) { - droppable.setDroppable(false); + orientable.setDropState(OrientableComponent::DropState::active); } else { - newY = axis - transformable.getH(); - ponderable.setVelocityY(0.0); - - if (ponderable.getState() == PonderableComponent::State::falling) - { - ponderable.setState(PonderableComponent::State::grounded); - } + touchedGround = true; } } else { - newY = axis - transformable.getH(); - ponderable.setVelocityY(0.0); - - if (ponderable.getState() == PonderableComponent::State::falling) - { - ponderable.setState(PonderableComponent::State::grounded); - } + touchedGround = true; } break; @@ -258,4 +258,11 @@ void PonderingSystem::processCollision( break; } } + + if (touchedGround) + { + newY = axis - transformable.getH(); + ponderable.setVelocityY(0.0); + ponderable.setGrounded(true); + } } -- cgit 1.4.1