Entity states
Having entities that are able to move around now implies they can either be standing still or moving. This quickly brings about the issue of entity states. Luckily, we have an elegant way of dealing with that, by introducing another component type and a system. Let's start by enumerating all possible entity states, and using the enumeration to establish a component type:
enum class EntityState{ Idle, Walking, Attacking, Hurt, Dying }; class C_State : public C_Base{ public: C_State(): C_Base(Component::State){} void ReadIn(std::stringstream& l_stream){ unsigned int state = 0; l_stream >> state; m_state = static_cast<EntityState>(state); } EntityState GetState() const { ... } void SetState(const EntityState& l_state){ ... } private: EntityState m_state; };
That's all we have to keep track of inside the component class. Time to move on to the system!
State system
Because state is not directly tethered to any other data...