From cb1421b91b2f8ffa71f7ee009dad4e237ed36e2c Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 6 Jul 2021 11:38:05 -0400 Subject: Added moonwalking to pathfinding behaviour This flag will make the sprite appear to be walking backwards. --- res/scripts/common.lua | 3 ++- src/behaviour_system.cpp | 5 +++++ src/behaviour_system.h | 3 ++- src/sprite.h | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 46f2275..559d8bd 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua @@ -48,7 +48,8 @@ ChangeMapOptions = { } PathfindingOptions = { - CARDINAL_DIRECTIONS_ONLY = 1 + CARDINAL_DIRECTIONS_ONLY = 1, + MOONWALKING = 2 -- Causes the sprite to walk backwards } gamestate = {} diff --git a/src/behaviour_system.cpp b/src/behaviour_system.cpp index ce980f6..f4dc388 100644 --- a/src/behaviour_system.cpp +++ b/src/behaviour_system.cpp @@ -7,6 +7,7 @@ #include "character_system.h" #include "direction.h" #include "transform_system.h" +#include "animation_system.h" bool pathfindingOptionsContains(PathfindingOptions options, PathfindingOptions value) { return (static_cast(options) & static_cast(value)) != 0; @@ -71,6 +72,9 @@ void BehaviourSystem::tick(double dt) { } else { if (sprite.characterState == CharacterState::Still || sprite.movementDir != sprite.path.front().dir) { game_.getSystem().moveInDirection(spriteId, sprite.path.front().dir); + if (sprite.moonwalking) { + game_.getSystem().setSpriteDirection(spriteId, oppositeDirection(sprite.path.front().dir)); + } } } } @@ -83,6 +87,7 @@ void BehaviourSystem::directSpriteToLocation(int spriteId, vec2i pos, Pathfindin sprite.behaviourType = BehaviourType::Path; sprite.pathfindingDestination = pos; sprite.cardinalDirectionsOnly = pathfindingOptionsContains(options, PathfindingOptions::CardinalDirectionsOnly); + sprite.moonwalking = pathfindingOptionsContains(options, PathfindingOptions::Moonwalking); createPath(spriteId); } diff --git a/src/behaviour_system.h b/src/behaviour_system.h index 1ddce4a..d338c79 100644 --- a/src/behaviour_system.h +++ b/src/behaviour_system.h @@ -7,7 +7,8 @@ enum class PathfindingOptions { None = 0, - CardinalDirectionsOnly = 1 << 0 + CardinalDirectionsOnly = 1 << 0, + Moonwalking = 1 << 1 }; class Game; diff --git a/src/sprite.h b/src/sprite.h index 406053e..86474ca 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -134,6 +134,7 @@ public: BehaviourType behaviourType = BehaviourType::None; vec2i pathfindingDestination; bool cardinalDirectionsOnly = false; + bool moonwalking = false; std::deque path; int followSpriteId = -1; -- cgit 1.4.1