summary refs log tree commit diff stats
path: root/src/behaviour_system.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/behaviour_system.cpp')
-rw-r--r--src/behaviour_system.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/behaviour_system.cpp b/src/behaviour_system.cpp new file mode 100644 index 0000000..8f17329 --- /dev/null +++ b/src/behaviour_system.cpp
@@ -0,0 +1,32 @@
1#include "behaviour_system.h"
2#include <random>
3#include "game.h"
4#include "character_system.h"
5#include "direction.h"
6
7void BehaviourSystem::tick(double dt) {
8 timer_.accumulate(dt);
9 while (timer_.step()) {
10 for (int spriteId : game_.getSprites()) {
11 Sprite& sprite = game_.getSprite(spriteId);
12 if (sprite.wander) {
13 // 75% chance of changing what's happening
14 if (std::bernoulli_distribution(0.75)(game_.getRng())) {
15 // 50% chance of choosing a direction or stopping
16 if (std::bernoulli_distribution(0.5)(game_.getRng())) {
17 Direction dir;
18 switch (std::uniform_int_distribution(0,3)(game_.getRng())) {
19 case 0: dir = Direction::left; break;
20 case 1: dir = Direction::up; break;
21 case 2: dir = Direction::right; break;
22 default: dir = Direction::down; break;
23 }
24 game_.getSystem<CharacterSystem>().moveInDirection(spriteId, dir);
25 } else {
26 game_.getSystem<CharacterSystem>().stopDirecting(spriteId);
27 }
28 }
29 }
30 }
31 }
32}