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 previous chapters, utilizing events for live input is really delayed and should never be used for anything else but checking for key presses that aren't time sensitive. Luckily, SFML provides means of obtaining the real-time state of...