I have been reading about networking for some time because multiplayer games are really fun. There is a few models to choose which one fits better for your game but I decided to try with server/client model.
I couldn't find an entire example (code) for what involves making a server/client multiplayer game but I've found a really useful information. These links really helped me to understand what was going on behind the scenes:
So I decided to try something just for learning purposes and the result is kind of good, actually. I could achieve something! Yeah, not a big deal but it was helpful to understand these things.
The Node.js server sends snapshots of the current game state to all the connected players several times per second, using a small structure to identify uniquely each instance of the game objects. Is responsible of keeping the game alive and serving the resources too.
The client was developed with Pixi.js 2D game engine. Consumes the snapshots provided by the server and handles all the game objects (populated with the game engine information) in the scene.
The communication between both sides is handled by socket.io.
Code and game
- You can play the game in Heroku where is hosted by free. Try the multiplayer stuff opening two browser tabs.
- The code is available at GitHub. Take a look, I hope it helps!
- More information here.
The assets being used are from Doom. None of them are from my property. I hope id Software doesn't take it bad. I'm trying to reach them to let them know about it. I've choosed them because are such an inspiration for me and they rock!
Take into account that anyone who wants to make a fast-paced multiplayer game would need to handle a LOT of things that I'm not showing here. The interpolation in this example is like a joke, seriously.
Please don't take anything as a rule because it could be wrong. Maybe there are better solutions. Remember, is my first time with networking and I'm kind of a newbie with game development. I've just wanted to share a code that is working.