Peoplemon  0.1.0
Peoplemon 3 game source documentation
SpinBehavior.cpp
Go to the documentation of this file.
2 
3 #include <BLIB/Util/Random.hpp>
4 #include <Core/Properties.hpp>
5 
6 namespace core
7 {
8 namespace component
9 {
11 : dir(dir)
12 , standTime(0.f) {}
13 
14 void SpinBehavior::update(bl::tmap::Position& position, Controllable& controller, float dt) {
15  standTime += dt;
16  if (standTime >= Properties::CharacterSpinPeriod()) {
17  standTime -= Properties::CharacterSpinPeriod();
18  switch (dir) {
20  controller.processControl(
21  input::fromDirection(nextClockwiseDirection(position.direction)));
22  } break;
23 
25  controller.processControl(
26  input::fromDirection(nextCounterClockwiseDirection(position.direction)));
27  } break;
28 
30  bl::tmap::Direction ndir =
31  static_cast<bl::tmap::Direction>(bl::util::Random::get<int>(0, 3));
32  while (ndir == position.direction) {
33  ndir = static_cast<bl::tmap::Direction>(bl::util::Random::get<int>(0, 3));
34  }
35  controller.processControl(input::fromDirection(ndir));
36  } break;
37 
38  default:
39  break;
40  }
41  }
42 }
43 
44 } // namespace component
45 } // namespace core
Core classes and functionality for both the editor and game.
EntityControl fromDirection(bl::tmap::Direction direction)
Helper method to convert a move direction to a control.
Definition: Control.cpp:36
Adding this component to an entity allows it to be controlled.
bool processControl(input::EntityControl command, bool sprint=false, bool overrideLock=false)
Processes the given command and manipulates the entity accordingly.
SpinBehavior(file::Behavior::Spinning::Direction dir)
Construct a new Spin Behavior component.
void update(bl::tmap::Position &position, Controllable &controller, float dt)
Updates the behavior.
Direction
The direction to spin.
Definition: Behavior.hpp:51
@ Random
The character spins randomly.
Definition: Behavior.hpp:59
@ Counterclockwise
The character spins counterclockwise.
Definition: Behavior.hpp:56
@ Clockwise
The character spins clockwise.
Definition: Behavior.hpp:53
static float CharacterSpinPeriod()
Definition: Properties.cpp:585