summary refs log tree commit diff stats
path: root/src/behaviour_system.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-03-09 11:51:34 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-03-09 11:51:34 -0500
commit89fc2da3f08fcd751ca069fde0987d193e59b007 (patch)
tree09d9f8c7fc44a72f3fa7677048a127286ac850a5 /src/behaviour_system.cpp
parentdd052d68e95f5b2128da272127e165c4a70f3f94 (diff)
downloadtanetane-89fc2da3f08fcd751ca069fde0987d193e59b007.tar.gz
tanetane-89fc2da3f08fcd751ca069fde0987d193e59b007.tar.bz2
tanetane-89fc2da3f08fcd751ca069fde0987d193e59b007.zip
Added "let's switch places!" Claus sprite
He will wander randomly until you get close, and will then run at you. Talking to him or bumping into him does nothing currently. If you move out of his range of interest he will go back to wandering at a walking pace.

#10
Diffstat (limited to 'src/behaviour_system.cpp')
-rw-r--r--src/behaviour_system.cpp33
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 }