Skip to content

johnfn/multiplayer.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

multiplayer.js

how2run

tsc --watch src/*.ts multiplayer-lib/*.ts

"omg making a multiplayer game is so hard johnfn"

NOT ANY MORE

multiplayer.js offers a simple way to structure your game project in such a way that making it multiplayer comes naturally.

First, you need to split up your game logic like this:

  1. Game data. All of the internal representations of your game entities go in here.

  2. Game update function. multiplayer.js wants a function defined like this:

    function update(data, events) {

Every tick it'll call that function, and it expects to receive back the updated data object. For example, if the data object is a unit and an enemy unit facing each other, and the event indicates that your unit should attack the enemy unit, then you should return an updated data object indicating your enemy is switching animations to the attack animation, that the enemy took damage, and so on.

  1. A way to render. But I need to figure this out still... ugh

Sometimes, you want to have variables that are specific to just one player. In that case, do something like this:

privateVariables = ['visible'];

function update() { 
    this.visible = this.near('unit', curPlayer);
}

This makes some magic happen on the server.

About

multiplayer games made hard! (instead of really hard!)

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors