Creating the structure for multiplayer

You must be fed up with networking theory by now, and you actually want to see some code! Right, it is now time to start the concrete implementation of our game server.

In order to extend our game and add an online mode to it, we went ahead and created a new state MultiplayerGameState, which is very similar to GameState at first. In the following code snippet, you see the important parts of the class definition. As you see, the three typical state-related methods to draw, update, and handle events are again there, as well as the variables for the world, window, and texture holder. Several variables are new related to the management of different players and socket connections:

class MultiplayerGameState : public ...

Get SFML Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.