When deciding on what kind of application i wanted to create using phaser framework, I decided I would create an online multiplayer game.
While discussing my project over with a friend who happens to be an expert in using phaser framework, we discussed the possibilities of the application and what would be required to achieve such a feat, after researching for awhile we found a way to create a basic HTML5 multiplayer game using phaser for the game development and eureca.io for client/server communication, this was to be my first in depth dive into this kind of development.
The game was based around multiplayer tank game, where user’s would join the game whenever they wanted and try to attack the other tanks that were in game. Now that wasn’t really what the tutorial was about, the tutorial gave information about using eureca.io and setting up how to have more than one player in the application. Eureca.io is an RPC library.
The practice game is based off a tutorial that is meant to help beginners get a grasp on creating an online game using phaser and eureca.io.
Firstly i had to create a new project in my htdocs, called it multiplayer. This was going to hold all the files for the game. Next I installed the assets required for this game and the tank script as i wasn’t too interested in the tank script and more interested in the other pieces of code, setting up eureca.io and learning about server set-ups.
I had to use the terminal a lot in this process to install various files. I started by creating a basic web server for the game, here we installed express library for nodejs, to make file service simpler. I had to used the terminal and change directory into the folder that had the game files.
Then run this command in the terminal : npm install express
I then created a server.js script and added it to the root directory of the game, and added the following code.
This starts the server for our game.
I then opened my browser for the test phase, using 127.0.0.1:8000 in the url, my browser opened up the practice game.
Next part was to install and prepare using eureca.io. Eureca.io can use either engine.io or sockjs as network transport layer, by default, engine.io is used. to use eureca.io with the default configuration we’ll need to install eureca.io and engine.io.
We do this in the terminal again using : npm install engine.io and npm install eureca.io.
After the install has completed we modify the server code and add eureca stuff before the server.listen(8000)
note: image of the specified code, as well as the code I added.
Note: code is edited later in tutorial.