Skip to content

croquet/croquet-for-web-guardians

Repository files navigation

Croquet Guardians

Guardians is an open-source cooperative multiplayer game
written by David A Smith
using the Croquet Worldcore game engine.

It features massive numbers of AI bots, taking advantage of
Croquet’s Synchronized Computation Architecture that uses only
client-side code, and where additional bots do not incur additional
network traffic or server load. From a Croquet programmer‘s point of view, there is no server.
All the multiplayer code is contained in this repository and Worldcore's, yet you won't find networking or server code in either.

This is the Web version of Guardians, there is also a Unity port.

Hack it

  1. install dependencies

     npm i
    
  2. edit apiKey.js with your API key from croquet.io/keys.

  3. run it

     npm start
    

The Game

The game is implemented using Worldcore.

The Lobby

The Lobby is implemented using plain Croquet (not Worldcore).

The lobby is a separate Croquet session. It shows a list of ongoing games.
When entering a game, it is loaded in an iframe inside the lobby.

The game will periodically send "croquet-lobby" window messages to its parent iframe, which the LobbyView will use to publish "in-app-session" events to its shared Lobby model. That game-session will be added to the Lobby's sessions Map by its name so other lobby users can see and join it. After a timeout the session will be removed from the map, unless another "in-app-session" event was received.

For a given game session, only one of its user will be "elected" to relay messages to the lobby (see LobbyRelayActor in src/Actors.js and LobbyRelayPawn in src/Pawns.js). All other users will leave the lobby session, and if one of them is elected, only that user will rejoin the lobby session. This ensures scaling for the lobby.

Questions

Please ask questions on our discord.