Creating a multiplayer game with node.js

So, I decided to put into practice what I’ve been learning of nodejs, and what better way than building something. That’s how I started coding this tank battle game.


The interface

The page was built as a simple bootstrap template. The players choose from one of three tanks and write a name. To join the game you tell a friend to open the same url.

In this game you control the tank using WASD keys and the mouse to aim and shoot, until you destroy other players tanks.

Tank selection

 Tank explosionThe code

There are two main parts for this game’s code: the server and the client.

The server listens to incoming connections and events using The client emits events to the server, for example when a new player joins the game.




The data for the bullets and tanks is managed by the server, which notifies all the players when a tank gets hit, or dies. The DOM is refreshed by each client, using the data received from the server. The data synchronization and DOM refreshing occurs periodically, using javascript ‘setInterval’ function.  



Feel free to contribute or fork this project on Github