GameKit  0.0.1a
C++ gamedev tools
MovementComponent.hpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: MovementComponent.hpp
5  *
6  * Description:
7  *
8  * Created: 17/01/2018 19:41:03
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #ifndef GK_MOVEMENTCOMPONENT_HPP_
15 #define GK_MOVEMENTCOMPONENT_HPP_
16 
17 #include <memory>
18 #include <stack>
19 
20 #include "gk/core/Vector2.hpp"
22 
23 namespace gk {
24 
26  public:
27  template<typename... Args>
28  bool push(Args &&...args) {
29  if(size() > 0 && top() && !top()->isFinished()) {
30  return false;
31  } else {
32  m_movements.emplace(args...);
33  return true;
34  }
35  }
36 
37  void pop() { m_movements.pop(); }
38 
39  std::unique_ptr<Movement> &top() { return m_movements.top(); }
40 
41  size_t size() const { return m_movements.size(); }
42 
43  private:
44  std::stack<std::unique_ptr<Movement>> m_movements;
45 };
46 
48  public:
50  movements.push(_movement);
51  }
52 
53  Vector2f v{0, 0};
54 
55  float speed = 1.0f;
56 
57  bool isMoving = false;
58  bool isDirectionLocked = false;
59 
61 
63 };
64 
65 } // namespace gk
66 
67 #endif // GK_MOVEMENTCOMPONENT_HPP_
std::stack< std::unique_ptr< Movement > > m_movements
MovementComponent(Movement *_movement)
std::unique_ptr< Movement > & top()
bool push(Args &&...args)