#include "behaviour_system.h" #include #include "game.h" #include "character_system.h" #include "direction.h" void BehaviourSystem::tick(double dt) { if (game_.isGameplayPaused()) return; timer_.accumulate(dt); while (timer_.step()) { for (int spriteId : game_.getSprites()) { Sprite& sprite = game_.getSprite(spriteId); if (sprite.wander && !sprite.paused) { // 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); } } } } } }