Peoplemon  0.1.0
Peoplemon 3 game source documentation
FixedPathBehavior.cpp
Go to the documentation of this file.
2 
3 namespace core
4 {
5 namespace component
6 {
8 : path(path)
9 , backwards(false)
10 , currentPace(0)
11 , currentStep(0) {}
12 
13 void FixedPathBehavior::update(bl::tmap::Position& position, Controllable& controller) {
14  if (path.paces.empty()) return;
15 
16  const bl::tmap::Direction moveDir = backwards ?
17  oppositeDirection(path.paces[currentPace].direction) :
18  path.paces[currentPace].direction;
19 
20  if (position.direction != moveDir) { controller.processControl(input::fromDirection(moveDir)); }
21  else {
22  if (controller.processControl(input::fromDirection(moveDir))) {
23  if (backwards) {
24  if (currentStep == 0) {
25  if (currentPace == 0) { backwards = false; }
26  else {
27  --currentPace;
28  currentStep = path.paces[currentPace].steps - 1;
29  }
30  }
31  else { --currentStep; }
32  }
33  else {
34  ++currentStep;
35  if (currentStep >= path.paces[currentPace].steps) {
36  currentStep = 0;
37  ++currentPace;
38  if (currentPace >= path.paces.size()) {
39  if (path.reverse) {
40  backwards = true;
41  currentPace = path.paces.size() - 1;
42  currentStep = path.paces.back().steps - 1;
43  }
44  else { currentPace = 0; }
45  }
46  }
47  }
48  }
49  }
50 }
51 
52 } // namespace component
53 } // 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.
void update(bl::tmap::Position &position, Controllable &controller)
Updates the entity along the path.
FixedPathBehavior(const file::Behavior::Path &path)
Construct a new Fixed Path Behavior component.
Contains data for when the behavior type is following a path.
Definition: Behavior.hpp:70
std::vector< Pace > paces
The sections of the path.
Definition: Behavior.hpp:95
bool reverse
True if the path should be done in reverse when completed, false to loop.
Definition: Behavior.hpp:98