Handling collisions
In order to make the game we're making feel like more than just entities moving across a static background with no consequences, collisions have to be checked for and handled. Within the ECS paradigm, this can be achieved by implementing a collidable component. For more flexibility, let's define multiple points that the collision box can be attached to:
enum class Origin{ Top_Left, Abs_Centre, Mid_Bottom };
The TOP_LEFT origin simply places the collision rectangle's top-left corner to the position provided. ABS_CENTRE moves that rectangle's centre to the position, and the MIDDLE_BOTTOM origin places it halfway through the x axis and all the way down the y axis. Consider the following illustration:
With this information, let us work on implementing the collidable component:
class C_Collidable : public C_Base{ public: C_Collidable(): C_Base(Component::Collidable), m_origin(Origin::Mid_Bottom), m_collidingOnX(false), m_collidingOnY(false){} void ReadIn...