Git Product home page Git Product logo

example-.io-game's Introduction

An Example .io Game
An Example .io Game

Build Status

An example multiplayer (.io) web game. Read the walkthrough: How to Build a Multiplayer (.io) Web Game.

Built with Node.js, socket.io, and HTML5 Canvas.

To see this code with Flow typing, visit the flow branch.

Development

To get started, make sure you have Node and NPM installed. Then,

$ npm install
$ npm run develop

on your local machine.

To run the project in a production setting, simply

$ npm install
$ npm run build
$ npm start

Tests

To run the tests for this this project, simply

$ npm install
$ npm test

example-.io-game's People

Contributors

dependabot[bot] avatar jahredhope avatar koelle25 avatar vzhou842 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

example-.io-game's Issues

Client side player.id is appended with `NaN` after interpolation

Summary:

NaN is appended to player.id on the client-side after interpolation. This happens after the second update is received from the server (i.e. the first time interpolation is performed).

Steps to reproduce:

  1. Add console.log(me.id); to the start of the render() function in src/client/render.js.
  2. Start the server with npm run develop from the command line.
  3. Visit localhost:3000.
  4. Open dev tools (ctrl + shift + j on Windows).
  5. Join the game by clicking on PLAY.

Expected results:

My socket id (e.g. ljLSqzmUSc5ZGEf5AAAC) is logged to console repeatedly.

Actual results:

  1. My socket id is logged to console 6 times (e.g. ljLSqzmUSc5ZGEf5AAAC).
  2. My socket id appended with NaN (e.g. ljLSqzmUSc5ZGEf5AAACNaN) is logged to console repeatedly.

Additional information:

I encountered this bug when trying to implement a chat feature. Each chat object had a reference to it's parentId without NaN appended to it. I was unable to match chat objects to players in the render() function in src/client/render.js because the player id's had changed to have NaN appended to them.

npm fail

can someone please help me

i copied my terminal emulator below

pi@raspberry:~$ git clone https://github.com/vzhou842/example-.io-game.git
Cloning into 'example-.io-game'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 632 (delta 0), reused 0 (delta 0), pack-reused 629
Receiving objects: 100% (632/632), 404.26 KiB | 0 bytes/s, done.
Resolving deltas: 100% (338/338), done.
pi@raspberry:~$ cd example-.io-game/
pi@raspberry:~/example-.io-game$ npm install
(node:6808) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
npm WARN package.json [email protected] No repository field.
npm ERR! Error: Method Not Allowed
npm ERR!     at errorResponse (/usr/share/npm/lib/cache/add-named.js:260:10)
npm ERR!     at /usr/share/npm/lib/cache/add-named.js:203:12
npm ERR!     at saved (/usr/share/npm/node_modules/npm-registry-client/lib/get.js:167:7)
npm ERR!     at FSReqWrap.oncomplete (fs.js:135:15)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/npm/npm/issues>

npm ERR! System Linux 4.19.66-v7+
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install"
npm ERR! cwd /home/pi/example-.io-game
npm ERR! node -v v8.11.1
npm ERR! npm -v 1.4.21
npm ERR! code E405
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/pi/example-.io-game/npm-debug.log
npm ERR! not ok code 0

Add Unit Tests

Title says it all. The project is modular enough that unit tests would be useful and should be easy to do.

Make it easy to remix on glitch

The tutorial is really great! One thing that I liked about it is that it is super close to being completely usable on glitch.com without changes.

You could make a glitch import from GitHub button: https://github-import.glitch.me/
That would let someone instantly clone the git the repo and have the example io game hosted for free. People can then immediately tweak and play around with it in the glitch online editor without even downloading or installing anything.

The only changes I needed to make to have it start in glitch was change package.json to build when the server starts:

 "start": "npm run build && cross-env NODE_ENV=production node src/server/server.js"

And change the websocket server to use wss in client/networking.js:

const socket = io(`wss://${window.location.host}`, { reconnection: false });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.