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 kinematics

The code we have written so far would only produce a static, unmoving scene. Since that isn't very exciting, let's work on adding potential for entity movement. Since it calls for more data being stored, we need another component type to work with:

class C_Movable : public C_Base{ public: C_Movable() : C_Base(Component::Movable), m_velocityMax(0.f), m_direction((Direction)0){} void ReadIn(std::stringstream& l_stream){ l_stream >> m_velocityMax >> m_speed.x >> m_speed.y; unsigned int dir = 0; l_stream >> dir; m_direction = static_cast<Direction>(dir); } ... void SetVelocity(const sf::Vector2f& l_vec){ ... } void SetMaxVelocity(float l_vel){ ... } void SetSpeed(const sf::Vector2f& l_vec){ ... } void SetAcceleration(const sf::Vector2f& ...

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