GithubHelp home page GithubHelp logo

itsacodeworld / node-online-game-template Goto Github PK

View Code? Open in Web Editor NEW

This project forked from huytd/node-online-game-template

0.0 1.0 0.0 6 KB

License: MIT License

CSS 29.91% HTML 13.11% JavaScript 56.98%

node-online-game-template's Introduction

NodeJS Online Game Template

Barebone NodeJS project for any multiplayer games.


UPDATE: I developed a lightweight alternative for Socket.IO, based on Engine.IO, the engine behind Socket.IO as well. It focus on transmiting binary data instead of string-based as in Socket.IO, so the target is to improve the networking performance. Unfortunatelly, I didn't have time for testing/integrating it yet. It would be nice if somebody can help me integrate it with this repo? Feel free to contact me for further discussion. Thank you so much!


Requirements

  • NodeJS / NPM
  • Socket.IO
  • ExpressJS

Getting started

  • Clone the source code from Github
  • Run npm install to install needed packages
  • Writing your code in server/server.js and client/js/game.js
  • Run your game server with npm start command

Server side

You can write all the server side code in server/server.js

io.on('connection', function (socket) {
  console.log("Somebody connected!");
  // Write your code here
});

Client side

For writing client side code, find client/js/game.js

There are 3 method to process your client logic: handleNetwork, handleLogic and handleGraphics

handleNetwork is where you receive and process all messages sent from Server:

Game.prototype.handleNetwork = function(socket) {
  console.log('Game connection process here');
  console.log(socket);
  // This is where you receive all socket messages
}

The socket is the connection object of your game client, use this to communicate with the server.

handleLogic is where you update your game logic (handling input, update game information,...)

Game.prototype.handleLogic = function() {
  console.log('Game is running');
  // This is where you update your game logic
}

handleGraphics is where you draw your game:

Game.prototype.handleGraphics = function(gfx) {
  // This is where you draw everything
}

License

This project is licensed under the terms of the MIT license. You can read the full license in LICENSE.md

node-online-game-template's People

Contributors

huytd avatar keneo avatar sorebit avatar

Watchers

 avatar

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.