All Projects → rameshvarun → Netplayjs

rameshvarun / Netplayjs

Make P2P multiplayer games in Javascript, no server hosting required. Powered by PeerJS and rollback netcode.

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to Netplayjs

Diztl
Share, discover & download files in your network 💥
Stars: ✭ 162 (-17.77%)
Mutual labels:  p2p
Dottorrent Gui
An advanced GUI torrent file creator with batch functionality, powered by PyQt and dottorrent
Stars: ✭ 175 (-11.17%)
Mutual labels:  p2p
Python Nat Hole Punching
UDP and TCP NAT hole punching examples in python
Stars: ✭ 190 (-3.55%)
Mutual labels:  p2p
Spitfire
An easy to use WebRTC Datachannels library for .NET applications.
Stars: ✭ 164 (-16.75%)
Mutual labels:  p2p
Peardownloader.js
一个支持多协议、多源、混合P2P-CDN的下载器
Stars: ✭ 170 (-13.71%)
Mutual labels:  p2p
Unstoppable Wallet Ios
A secure and decentralized Bitcoin and other cryptocurrency wallet for iPhone. Supports Bitcoin, Ethereum, EOS, Binance Chain, Bitcoin Cash, DASH, ...
Stars: ✭ 180 (-8.63%)
Mutual labels:  p2p
P2pt
Simple WebRTC Peer 2 Peer connections using WebTorrent trackers as the signalling server. Use WebTorrent trackers for any kind of WebRTC app ! 🔥 Make WebRTC apps fast & easy ! 🚀⭐
Stars: ✭ 159 (-19.29%)
Mutual labels:  p2p
Peerlinks
Distributed Secure IRC | Protocol Implementation
Stars: ✭ 193 (-2.03%)
Mutual labels:  p2p
Luminance
Stars: ✭ 173 (-12.18%)
Mutual labels:  p2p
Arewedistributedyet
Website + Community effort to unlock the peer-to-peer web at arewedistributedyet.com ⚡🌐🔑
Stars: ✭ 189 (-4.06%)
Mutual labels:  p2p
Torrentpier
Main project repository
Stars: ✭ 166 (-15.74%)
Mutual labels:  p2p
Unstoppable Wallet Android
A secure and decentralized Bitcoin and other cryptocurrency wallet for Android phones. Supports Bitcoin, Ethereum, EOS, Binance Chain, Bitcoin Cash, DASH, ...
Stars: ✭ 165 (-16.24%)
Mutual labels:  p2p
Sharethem
File Sharing & Transfer made a lot easier
Stars: ✭ 181 (-8.12%)
Mutual labels:  p2p
Rapidbay
Self-hosted torrent video streaming service compatible with Chromecast and AppleTV deployable in the cloud
Stars: ✭ 163 (-17.26%)
Mutual labels:  p2p
Netflux
JavaScript client and server side transport API based on WebRTC & WebSocket
Stars: ✭ 188 (-4.57%)
Mutual labels:  p2p
Pikachu Volleyball P2p Online
Pikachu Volleyball peer-to-peer online via WebRTC data channels
Stars: ✭ 160 (-18.78%)
Mutual labels:  p2p
Torrent Discovery
Discover BitTorrent and WebTorrent peers
Stars: ✭ 177 (-10.15%)
Mutual labels:  p2p
Mediadevices
Go implementation of the MediaDevices API.
Stars: ✭ 197 (+0%)
Mutual labels:  p2p
React Peer
Send data to someone else's browser as easy as setting state
Stars: ✭ 191 (-3.05%)
Mutual labels:  p2p
Gun
An open source cybersecurity protocol for syncing decentralized graph data.
Stars: ✭ 15,172 (+7601.52%)
Mutual labels:  p2p

(WIP) NetplayJS

Build Status npm

Make peer-to-peer WebRTC-based multiplayer games in Javascript, no server hosting or network synchronization code required! Powered by PeerJS.

CHECK THE DEMOS

NetplayJS consists of:

  • Implementations of Rollback netcode and Lockstep netcode in Javascript
  • A prototyping framework that lets you create a multiplayer game in a few lines of code
  • A collection of demos built in the prototyping framework

Quick Start

Let's make a quick game in the prototyping framework. Add this script tag to your HTML.

<script src="https://unpkg.com/[email protected]/dist/netplay.js"></script>

Add this javascript code.

class SimpleGame extends netplayjs.Game {
  // In the constructor, we initialize the state of our game.
  constructor() {
    super();
    // Initialize our player positions.
    this.aPos = { x: 100, y: 150 };
    this.bPos = { x: 500, y: 150 };
  }

  // The tick function takes a map of Player -> Input and
  // simulates the game forward. Think of it like making
  // a local multiplayer game with multiple controllers.
  tick(playerInputs) {
    for (const [player, input] of playerInputs.entries()) {
      // Generate player velocity from input keys.
      const vel = {
        x:
          (input.pressed.ArrowLeft ? -1 : 0) +
          (input.pressed.ArrowRight ? 1 : 0),
        y:
          (input.pressed.ArrowDown ? -1 : 0) +
          (input.pressed.ArrowUp ? 1 : 0),
      };

      // Apply the velocity to the appropriate player.
      if (player.getID() == 0) {
        this.aPos.x += vel.x * 5;
        this.aPos.y -= vel.y * 5;
      } else if (player.getID() == 1) {
        this.bPos.x += vel.x * 5;
        this.bPos.y -= vel.y * 5;
      }
    }
  }

  // Normally, we have to implement a serialize / deserialize function
  // for our state. However, there is an autoserializer that can handle
  // simple states for us. We don't need to do anything here!
  // serialize() {}
  // deserialize(value) {}

  // Draw the state of our game onto a canvas.
  draw(canvas) {
    const ctx = canvas.getContext("2d");

    // Fill with black.
    ctx.fillStyle = "black";
    ctx.fillRect(0, 0, canvas.width, canvas.height);

    // Draw squares for the players.
    ctx.fillStyle = "red";
    ctx.fillRect(this.aPos.x - 5, this.aPos.y - 5, 10, 10);
    ctx.fillStyle = "blue";
    ctx.fillRect(this.bPos.x - 5, this.bPos.y - 5, 10, 10);
  }
}

SimpleGame.timestep = 1000 / 60; // Our game runs at 60 FPS
SimpleGame.canvasSize = { width: 600, height: 300 };

// Because our game can be easily rewound, we will use Rollback netcode
// If your game cannot be rewound, you should use LockstepWrapper instead.
new netplayjs.RollbackWrapper(SimpleGame).start();

And voila - a real-time networked game with rollback and client-side prediction.

Basic Usage

NetplayJS is powered by an implementation of Rollback netcode (like GGPO) in Javascript. The library is written in TypeScript, and it is highly recommended that you use it with TypeScript as well.

Installation

npm install --save netplayjs
import { NetplayPlayer, DefaultInput, Game, RollbackWrapper } from "netplayjs";

Game State Serialization

The client-side prediction and rewind capabilities of netplayjs are based off of the ability to serialize and deserialize the state of the game. In the simple example above, the autoserializer can take care of rewinding our states and sending them over a network. For most games, however, you will need to implement your own logic. You can do this by overriding Game.serialize and Game.deserialize in your subclass.

Advanced Usage

If you want to integrate rollback into an existing game, or otherwise find the prototyping framework too restrictive, you can use the core netcode implementations. These implementations are abstract enough to be used in any project.

let rollbackNetcode = new RollbackNetcode(...)
rollbackNetcode.start();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].