Trying to tune turning.

This commit is contained in:
2024-09-11 10:07:23 -05:00
parent ad3974bde5
commit b309478922
2 changed files with 12 additions and 3 deletions

View File

@ -66,8 +66,14 @@ struct EntityStepResult Entity::move(
) { ) {
assertFalse(this->isMoving(), "Entity is already moving."); assertFalse(this->isMoving(), "Entity is already moving.");
struct EntityStepResult result; 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) { switch(direction) {
case EntityDirection::Up: case EntityDirection::Up:
newPosition.z--; newPosition.z--;
@ -90,7 +96,6 @@ struct EntityStepResult Entity::move(
if(entityInWay) { if(entityInWay) {
result.type = EntityStepResultType::EntityInWay; result.type = EntityStepResultType::EntityInWay;
result.entityInWay = entityInWay; result.entityInWay = entityInWay;
this->turn(direction);
return result; return result;
} }
@ -100,7 +105,6 @@ struct EntityStepResult Entity::move(
// Move the entity to the new tile. // Move the entity to the new tile.
this->lastTilePosition = this->tilePosition; this->lastTilePosition = this->tilePosition;
this->tilePosition = newPosition; this->tilePosition = newPosition;
this->direction = direction;
this->stepTime = 1.0f; this->stepTime = 1.0f;
this->stepSpeed = stepSpeed; this->stepSpeed = stepSpeed;
@ -110,6 +114,8 @@ struct EntityStepResult Entity::move(
void Entity::turn(const enum EntityDirection direction) { void Entity::turn(const enum EntityDirection direction) {
this->direction = direction; this->direction = direction;
this->turnTime = ENTITY_TURN_TIME;
this->eventTurn.emit();
} }
void Entity::setPosition(struct EntityTilePosition pos) { void Entity::setPosition(struct EntityTilePosition pos) {

View File

@ -11,6 +11,7 @@
#define ENTITY_STEP_SPEED_DEFAULT 3.0f #define ENTITY_STEP_SPEED_DEFAULT 3.0f
#define ENTITY_STEP_SPEED_RUNNING 6.0f #define ENTITY_STEP_SPEED_RUNNING 6.0f
#define ENTITY_TURN_TIME 0.06f
namespace Dawn { namespace Dawn {
class World; class World;
@ -24,6 +25,7 @@ namespace Dawn {
}; };
enum class EntityStepResultType { enum class EntityStepResultType {
Turn,
Step, Step,
EntityInWay, EntityInWay,
}; };
@ -54,6 +56,7 @@ namespace Dawn {
Event<> eventStepStart; Event<> eventStepStart;
Event<> eventStepEnd; Event<> eventStepEnd;
Event<> eventMove; Event<> eventMove;
Event<> eventTurn;
void onInit() override; void onInit() override;
void onDispose() override; void onDispose() override;