From 996076cf151a27a7a8d278aa4d15b28cfb196c46 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 20 Feb 2021 13:04:41 -0500 Subject: Added a randomly wandering Ionia to the map --- src/behaviour_system.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/behaviour_system.cpp (limited to 'src/behaviour_system.cpp') 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 @@ +#include "behaviour_system.h" +#include +#include "game.h" +#include "character_system.h" +#include "direction.h" + +void BehaviourSystem::tick(double dt) { + timer_.accumulate(dt); + while (timer_.step()) { + for (int spriteId : game_.getSprites()) { + Sprite& sprite = game_.getSprite(spriteId); + if (sprite.wander) { + // 75% chance of changing what's happening + if (std::bernoulli_distribution(0.75)(game_.getRng())) { + // 50% chance of choosing a direction or stopping + if (std::bernoulli_distribution(0.5)(game_.getRng())) { + Direction dir; + switch (std::uniform_int_distribution(0,3)(game_.getRng())) { + case 0: dir = Direction::left; break; + case 1: dir = Direction::up; break; + case 2: dir = Direction::right; break; + default: dir = Direction::down; break; + } + game_.getSystem().moveInDirection(spriteId, dir); + } else { + game_.getSystem().stopDirecting(spriteId); + } + } + } + } + } +} -- cgit 1.4.1