diff options
Diffstat (limited to 'src/behaviour_system.cpp')
| -rw-r--r-- | src/behaviour_system.cpp | 33 |
1 files changed, 19 insertions, 14 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 | } |
