SpaceshipsOnline is a simple multiplayer space game implemented from scratch with Node.JS and Socket.io. Both client and server are written in Typescript. We use browserify to bundle the client into a javascript file. We use ESLint and prettier to keep the code clean.
I was inspired to write this game after reading excellent articles by Glenn Fiedler and Yahn W. Bernier:
- Networked Physics
- What Every Programmer Needs To Know About Game Networking
- Snapshot Interpolation
- Latency Compensating Methods
- Install node.js and NPM
- In the root directory, run
npm install
For now, I just wrote several scripts in package.json
. These scripts are made cross-platform through the shx NPM package.
npm run lint
: Run the linter and quietly fix any fixable warningsnpm run clean
: Deletes thedist
folder, if it existsnpm run pre-build
: Creates thedist
folder structurenpm run build-server
: Usetsc
to transpile the server code. Also copies theassets
folder intodist
npm run build-client
: Usetsc
andbrowserify
to transpile the client code and package it into a single Javascript file
I often combine these commands for convenience:
npm run clean && npm run pre-build && npm run build-server && npm run build-client && npm start
This will create a dist
folder with the following structure:
server
: transpiled server codeshared
: transpiled "shared" code used by the serverassets
: assets (e.g. images) used by the clientclient
: transpiled client code (contains "client.js")index.html
: the HTML file served by the backend. Simply creates an HTML5 canvas and loads theclient/client.js
script from the server
In the root directory, run npm start
You can now join the game at http://localhost:8081