YAPOG  0.0.1
Yet Another Pokemon Online Game
CharacterMoveController.cpp
Go to the documentation of this file.
2 
3 namespace yap
4 {
7 
10  , directions_ ()
11  , lastDirection_ (DEFAULT_LAST_DIRECTION)
12  {
13  directions_.Add (Direction::North, false);
17  }
18 
20  {
21  }
22 
24  {
25  directions_[direction] = true;
26 
27  lastDirection_ = direction;
28 
29  Update ();
30  }
31 
33  {
34  directions_[direction] = false;
35 
36  Update ();
37  }
38 
40  {
41  int enabledDirectionCount = 0;
42  Direction currentDirection = lastDirection_;
43 
44  for (auto& it : directions_)
45  {
46  if (!it.second)
47  continue;
48 
49  ++enabledDirectionCount;
50 
51  currentDirection = it.first;
52  }
53 
54  if (enabledDirectionCount == 0)
55  {
56  force_ = Vector2 ();
57  return;
58  }
59 
60  if (enabledDirectionCount > 1)
61  currentDirection = lastDirection_;
62 
63  switch (currentDirection)
64  {
65  case Direction::North: force_ = Vector2 (0.0f, -value_.y); break;
66  case Direction::East: force_ = Vector2 (value_.x, 0.0f); break;
67  case Direction::South: force_ = Vector2 (0.0f, value_.y); break;
68  case Direction::West: force_ = Vector2 (-value_.x, 0.0f); break;
69  default: break;
70  }
71  }
72 } // namespace yap