diff --git a/src/dawnrpg/component/entity/Entity.cpp b/src/dawnrpg/component/entity/Entity.cpp index fa87a8ee..f176d9d0 100644 --- a/src/dawnrpg/component/entity/Entity.cpp +++ b/src/dawnrpg/component/entity/Entity.cpp @@ -66,8 +66,14 @@ struct EntityStepResult Entity::move( ) { assertFalse(this->isMoving(), "Entity is already moving."); struct EntityStepResult result; - struct EntityTilePosition newPosition = this->tilePosition; + if(this->direction != direction) { + this->turn(direction); + result.type = EntityStepResultType::Turn; + return result; + } + + struct EntityTilePosition newPosition = this->tilePosition; switch(direction) { case EntityDirection::Up: newPosition.z--; @@ -90,7 +96,6 @@ struct EntityStepResult Entity::move( if(entityInWay) { result.type = EntityStepResultType::EntityInWay; result.entityInWay = entityInWay; - this->turn(direction); return result; } @@ -100,7 +105,6 @@ struct EntityStepResult Entity::move( // Move the entity to the new tile. this->lastTilePosition = this->tilePosition; this->tilePosition = newPosition; - this->direction = direction; this->stepTime = 1.0f; this->stepSpeed = stepSpeed; @@ -110,6 +114,8 @@ struct EntityStepResult Entity::move( void Entity::turn(const enum EntityDirection direction) { this->direction = direction; + this->turnTime = ENTITY_TURN_TIME; + this->eventTurn.emit(); } void Entity::setPosition(struct EntityTilePosition pos) { diff --git a/src/dawnrpg/component/entity/Entity.hpp b/src/dawnrpg/component/entity/Entity.hpp index 3d79430b..dae48fe8 100644 --- a/src/dawnrpg/component/entity/Entity.hpp +++ b/src/dawnrpg/component/entity/Entity.hpp @@ -11,6 +11,7 @@ #define ENTITY_STEP_SPEED_DEFAULT 3.0f #define ENTITY_STEP_SPEED_RUNNING 6.0f +#define ENTITY_TURN_TIME 0.06f namespace Dawn { class World; @@ -24,6 +25,7 @@ namespace Dawn { }; enum class EntityStepResultType { + Turn, Step, EntityInWay, }; @@ -54,6 +56,7 @@ namespace Dawn { Event<> eventStepStart; Event<> eventStepEnd; Event<> eventMove; + Event<> eventTurn; void onInit() override; void onDispose() override;