O'Reilly logo

Mastering SFML Game Development by Raimondas Pupius

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required