An Entity System

As part of an exercise using SFML I received a rather simple task of collision detection with rectangles for the week, as well as the use of some vectors (In this case point-based, not array-like vectors). What I did initially was create a player instance and a few ‘buildings’ for collision testing.

What I also did was incorporate a little entity system that I’m quite happy with. The only thing required to add an entity now is _entManager.AddEntity(entity_type,xPos,yPos,)_. Although this would seem rather limited it does everything I need to do for a while. The difference between this and my regular work is that regardless of using SFML, it does not restrict anything from the programmer and in this case there is no such thing as an entity system already.

An abstract base class, in this case a WorldObject serves as the base of each entity type. It assigns a collision rectangle and a unique ID. This way, I can add as many instances of an entity without having to worry about naming problems, and the collision system is automatically set up as well.

Right now I’m using a static cast to convert the ‘WorldObject’ that the player class inherits from back to the player, which might not be the greatest design method but it works.