summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2021-07-06 11:38:05 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2021-07-06 11:38:05 -0400
commitcb1421b91b2f8ffa71f7ee009dad4e237ed36e2c (patch)
tree9530d017f4230fabf29baf547533a2c8173aface /src
parentc77c50df34b598014e29f889523bbf067a0998f0 (diff)
downloadtanetane-cb1421b91b2f8ffa71f7ee009dad4e237ed36e2c.tar.gz
tanetane-cb1421b91b2f8ffa71f7ee009dad4e237ed36e2c.tar.bz2
tanetane-cb1421b91b2f8ffa71f7ee009dad4e237ed36e2c.zip
Added moonwalking to pathfinding behaviour
This flag will make the sprite appear to be walking backwards.
Diffstat (limited to 'src')
-rw-r--r--src/behaviour_system.cpp5
-rw-r--r--src/behaviour_system.h3
-rw-r--r--src/sprite.h1
3 files changed, 8 insertions, 1 deletions
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 @@
7#include "character_system.h" 7#include "character_system.h"
8#include "direction.h" 8#include "direction.h"
9#include "transform_system.h" 9#include "transform_system.h"
10#include "animation_system.h"
10 11
11bool pathfindingOptionsContains(PathfindingOptions options, PathfindingOptions value) { 12bool pathfindingOptionsContains(PathfindingOptions options, PathfindingOptions value) {
12 return (static_cast<int>(options) & static_cast<int>(value)) != 0; 13 return (static_cast<int>(options) & static_cast<int>(value)) != 0;
@@ -71,6 +72,9 @@ void BehaviourSystem::tick(double dt) {
71 } else { 72 } else {
72 if (sprite.characterState == CharacterState::Still || sprite.movementDir != sprite.path.front().dir) { 73 if (sprite.characterState == CharacterState::Still || sprite.movementDir != sprite.path.front().dir) {
73 game_.getSystem<CharacterSystem>().moveInDirection(spriteId, sprite.path.front().dir); 74 game_.getSystem<CharacterSystem>().moveInDirection(spriteId, sprite.path.front().dir);
75 if (sprite.moonwalking) {
76 game_.getSystem<AnimationSystem>().setSpriteDirection(spriteId, oppositeDirection(sprite.path.front().dir));
77 }
74 } 78 }
75 } 79 }
76 } 80 }
@@ -83,6 +87,7 @@ void BehaviourSystem::directSpriteToLocation(int spriteId, vec2i pos, Pathfindin
83 sprite.behaviourType = BehaviourType::Path; 87 sprite.behaviourType = BehaviourType::Path;
84 sprite.pathfindingDestination = pos; 88 sprite.pathfindingDestination = pos;
85 sprite.cardinalDirectionsOnly = pathfindingOptionsContains(options, PathfindingOptions::CardinalDirectionsOnly); 89 sprite.cardinalDirectionsOnly = pathfindingOptionsContains(options, PathfindingOptions::CardinalDirectionsOnly);
90 sprite.moonwalking = pathfindingOptionsContains(options, PathfindingOptions::Moonwalking);
86 91
87 createPath(spriteId); 92 createPath(spriteId);
88} 93}
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 @@
7 7
8enum class PathfindingOptions { 8enum class PathfindingOptions {
9 None = 0, 9 None = 0,
10 CardinalDirectionsOnly = 1 << 0 10 CardinalDirectionsOnly = 1 << 0,
11 Moonwalking = 1 << 1
11}; 12};
12 13
13class Game; 14class 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:
134 BehaviourType behaviourType = BehaviourType::None; 134 BehaviourType behaviourType = BehaviourType::None;
135 vec2i pathfindingDestination; 135 vec2i pathfindingDestination;
136 bool cardinalDirectionsOnly = false; 136 bool cardinalDirectionsOnly = false;
137 bool moonwalking = false;
137 std::deque<PathfindingInstruction> path; 138 std::deque<PathfindingInstruction> path;
138 int followSpriteId = -1; 139 int followSpriteId = -1;
139 140