decentraland-scenes / Land-Flipper-Game

A multiplayer game with websockets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Land Flipper Game

A multiplayer game with Colyseus for websockets multiplayer messaging. The game logic is carried out server-side.

demo

This scene shows you:

  • How to support Colyseus in a Decentraland scene
  • How to set up a simple game logic in Colyseus
  • How to handle game state changes from the server in your scene
  • How to fetch a player's realm
  • How to keep track of the state of each realm as a separate room in your game
  • How to handle team formation, scoring and time limits from the server

The server takes care of organizing players into teams and only starting a match when there are players on both sides.

Each scene runs its own calculations of the current remaining time and the scores of each team, but so does the server. In the end, the server has the final word about when the match is over and what is the final result.

Try it out

Install the CLI

Download and install the Decentraland CLI by running the following command:

$ npm i -g decentraland

Run the server locally

$ cd server
$ npm run build
$ npm run start

NOTE: If this is your first time running the scene then you need to run npm install before npm start

Run the scene

Keep the server running, run the scene on a separate command line window:

$ cd scene
$ dcl start

Scene Usage

Open two separate browser windows, and direct one player to the Blue tile and another to the Red tile, so that there are players in both teams.

Using Colyseus SDK with Decentraland

Install colyseus.js:

npm install --save colyseus.js

Add colyseus.js to your "bundleDependencies" in your package.json:

  "bundleDependencies": [
    "colyseus.js"
  ]

To avoid TypeScript compilation errors you'll need to edit tsconfig.json, and include a few ///<reference to your source-code, as you can see in the scene/src/connection.ts file.

{
  "compilerOptions": {
    // ...
    "noLib": false,
    // ...
  }
}
///<reference lib="es2015.symbol" />
///<reference lib="es2015.symbol.wellknown" />
///<reference lib="es2015.collection" />
///<reference lib="es2015.iterable" />

import { Client } from "colyseus.js";

The Colyseus SDK requires a few TypeScript libraries that are excluded by default by Decentraland.


Creating a Colyseus server:

npm init colyseus-app ./server

Deploying to Colyseus Arena

npm run build

Upload the lib folder from the Arena control panel.

More

Learn more about how to build your own scenes in our documentation site.

If something doesn’t work, please file an issue.

Copyright info

This scene is protected with a standard Apache 2 licence. See the terms and conditions in the LICENSE file.

About

A multiplayer game with websockets


Languages

Language:TypeScript 67.6%Language:JavaScript 31.0%Language:Dockerfile 1.2%Language:Shell 0.2%