O'Reilly logo

SFML Game Development By Example 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

Time to integrate

Much like how a hammer is useless without someone using it, so are our two classes without being properly adopted by the Game class. Since we didn't write all that code just to practise typing, let's work on putting all the pieces together. First, we need to actually add two new members to the Game class, and you might already have guessed what they are:

class Game{
...
private:
...
    World m_world;
    Snake m_snake;
};

Next, let's initialize these members. Since both of them have constructors that take arguments, it's the time for initializer list:

Game::Game(): m_window("Snake", sf::Vector2u(800, 600)),m_snake(m_world.GetBlockSize()),m_world(sf::Vector2u(800,600))
{
    ...
}

Next, we need to process some input. As you may recall from the ...

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