diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/behaviour_system.cpp | 33 | ||||
| -rw-r--r-- | src/script_system.cpp | 4 | ||||
| -rw-r--r-- | src/sprite.h | 4 |
3 files changed, 25 insertions, 16 deletions
| diff --git a/src/behaviour_system.cpp b/src/behaviour_system.cpp index b68cd6d..f4f7546 100644 --- a/src/behaviour_system.cpp +++ b/src/behaviour_system.cpp | |||
| @@ -19,22 +19,27 @@ void BehaviourSystem::tick(double dt) { | |||
| 19 | while (timer_.step()) { | 19 | while (timer_.step()) { |
| 20 | for (int spriteId : game_.getSprites()) { | 20 | for (int spriteId : game_.getSprites()) { |
| 21 | Sprite& sprite = game_.getSprite(spriteId); | 21 | Sprite& sprite = game_.getSprite(spriteId); |
| 22 | if (!sprite.paused && sprite.behaviourType == BehaviourType::Wander) { | 22 | if (!sprite.paused) { |
| 23 | // 75% chance of changing what's happening | 23 | if (sprite.behaviourType == BehaviourType::Wander) { |
| 24 | if (std::bernoulli_distribution(0.75)(game_.getRng())) { | 24 | // 75% chance of changing what's happening |
| 25 | // 50% chance of choosing a direction or stopping | 25 | if (std::bernoulli_distribution(0.75)(game_.getRng())) { |
| 26 | if (std::bernoulli_distribution(0.5)(game_.getRng())) { | 26 | // 50% chance of choosing a direction or stopping |
| 27 | Direction dir; | 27 | if (std::bernoulli_distribution(0.5)(game_.getRng())) { |
| 28 | switch (std::uniform_int_distribution(0,3)(game_.getRng())) { | 28 | Direction dir; |
| 29 | case 0: dir = Direction::left; break; | 29 | switch (std::uniform_int_distribution(0,3)(game_.getRng())) { |
| 30 | case 1: dir = Direction::up; break; | 30 | case 0: dir = Direction::left; break; |
| 31 | case 2: dir = Direction::right; break; | 31 | case 1: dir = Direction::up; break; |
| 32 | default: dir = Direction::down; break; | 32 | case 2: dir = Direction::right; break; |
| 33 | default: dir = Direction::down; break; | ||
| 34 | } | ||
| 35 | game_.getSystem<CharacterSystem>().moveInDirection(spriteId, dir); | ||
| 36 | } else { | ||
| 37 | game_.getSystem<CharacterSystem>().stopDirecting(spriteId); | ||
| 33 | } | 38 | } |
| 34 | game_.getSystem<CharacterSystem>().moveInDirection(spriteId, dir); | ||
| 35 | } else { | ||
| 36 | game_.getSystem<CharacterSystem>().stopDirecting(spriteId); | ||
| 37 | } | 39 | } |
| 40 | } else if (sprite.behaviourType == BehaviourType::Follow) { | ||
| 41 | Sprite& target = game_.getSprite(sprite.followSpriteId); | ||
| 42 | game_.getSystem<CharacterSystem>().moveInDirection(spriteId, directionFacingPoint(target.loc - sprite.loc)); | ||
| 38 | } | 43 | } |
| 39 | } | 44 | } |
| 40 | } | 45 | } |
| diff --git a/src/script_system.cpp b/src/script_system.cpp index 50ea60a..a50fa7a 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp | |||
| @@ -52,7 +52,8 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { | |||
| 52 | "enclosureZone", &Sprite::enclosureZone, | 52 | "enclosureZone", &Sprite::enclosureZone, |
| 53 | "movementSpeed", &Sprite::movementSpeed, | 53 | "movementSpeed", &Sprite::movementSpeed, |
| 54 | "solid", &Sprite::solid, | 54 | "solid", &Sprite::solid, |
| 55 | "behaviourType", &Sprite::behaviourType); | 55 | "behaviourType", &Sprite::behaviourType, |
| 56 | "followSpriteId", &Sprite::followSpriteId); | ||
| 56 | 57 | ||
| 57 | engine_.new_usertype<MessageSystem>( | 58 | engine_.new_usertype<MessageSystem>( |
| 58 | "message", | 59 | "message", |
| @@ -242,6 +243,7 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { | |||
| 242 | loadMapScripts(filename); | 243 | loadMapScripts(filename); |
| 243 | }); | 244 | }); |
| 244 | 245 | ||
| 246 | engine_.set_function("directionFacingPoint", &directionFacingPoint); | ||
| 245 | engine_.set_function("cardinalDirectionFacingPoint", &cardinalDirectionFacingPoint); | 247 | engine_.set_function("cardinalDirectionFacingPoint", &cardinalDirectionFacingPoint); |
| 246 | 248 | ||
| 247 | engine_.script_file("../res/scripts/common.lua"); | 249 | engine_.script_file("../res/scripts/common.lua"); |
| diff --git a/src/sprite.h b/src/sprite.h index 2ab306d..10dd3a8 100644 --- a/src/sprite.h +++ b/src/sprite.h | |||
| @@ -45,7 +45,8 @@ enum class CharacterMedium { | |||
| 45 | enum class BehaviourType { | 45 | enum class BehaviourType { |
| 46 | None, | 46 | None, |
| 47 | Wander, | 47 | Wander, |
| 48 | Path | 48 | Path, |
| 49 | Follow | ||
| 49 | }; | 50 | }; |
| 50 | 51 | ||
| 51 | enum class MirrorType { | 52 | enum class MirrorType { |
| @@ -128,6 +129,7 @@ public: | |||
| 128 | vec2i pathfindingDestination; | 129 | vec2i pathfindingDestination; |
| 129 | bool cardinalDirectionsOnly = false; | 130 | bool cardinalDirectionsOnly = false; |
| 130 | std::deque<PathfindingInstruction> path; | 131 | std::deque<PathfindingInstruction> path; |
| 132 | int followSpriteId = -1; | ||
| 131 | 133 | ||
| 132 | // Mirror | 134 | // Mirror |
| 133 | MirrorType mirrorType = MirrorType::None; | 135 | MirrorType mirrorType = MirrorType::None; |
