Within the entity component system paradigm, movement of a particular body is quantified by all the forces imposed on it. The collection of these forces can be represented by a movable component:
class C_Movable : public C_Base{ public: ... private: sf::Vector2f m_velocity; float m_velocityMax; sf::Vector2f m_speed; sf::Vector2f m_acceleration; Direction m_direction; };
This component takes away physics elements from the second project of this book, namely the velocity, speed and acceleration attributes. In order to simplify the code, the velocity cap is represented by a single float this time, as it is unlikely we will ever need to limit the velocity differently based on its axis.
Let's take a look at the rest of the movable component class:
C_Movable() : C_Base(Component::Movable), m_velocityMax(0.f), m_direction((Direction)0) {}
The constructor here initializes the data members to some default values, which are later replaced by ones from...