summary refs log tree commit diff stats
path: root/src/behaviour_system.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-20 13:04:41 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-20 13:04:41 -0500
commit996076cf151a27a7a8d278aa4d15b28cfb196c46 (patch)
tree96a2fdcf3fd5a22394313d140cacc0257a821543 /src/behaviour_system.cpp
parentee802c01d3008e6019bc55a02fcc2e6d68b288d1 (diff)
downloadtanetane-996076cf151a27a7a8d278aa4d15b28cfb196c46.tar.gz
tanetane-996076cf151a27a7a8d278aa4d15b28cfb196c46.tar.bz2
tanetane-996076cf151a27a7a8d278aa4d15b28cfb196c46.zip
Added a randomly wandering Ionia to the map
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}