Skip to content

Latest commit

 

History

History
 
 

asteroids-rivet

Rivet Asteroids Example

This repo contains an example of a fully multiplayer game running as a Discord activity via Rivet's gaming infrastructure that lets you host your game in just two commands.

Client architecture

  • ViteJS

Server architecture

  • Express
  • Socket.io

Setting up your Discord Application

Before we write any code, lets follow the instructions here to make sure your Discord application is set up correctly.

Setting up your environment variables

In this directory (/examples/asteroids-rivet) we need to create a .env file with the OAuth2 variables, as described here.

DISCORD_CLIENT_ID=123456789012345678
DISCORD_CLIENT_SECRET=abcdefghijklmnopqrstuvwxyzabcdef

Running your app locally

Deploying your game

First, we deploy the game to Rivet with the Rivet CLI. See how to install the Rivet CLI here.

After installation, run this command to get your project linked to Rivet Cloud. You will be asked to sign in and create a game to link to.

rivet init

Next, we can deploy to Rivet:

rivet deploy prod

If successful, you should see a message in your terminal that looks like so:

Deploy Succeeded https://asteroids-xxx.rivet.game/

Updating your URL mappings

Using the URL of the successfully deployed game, you can update your activity's URL mappings to match like so:

Screenshot of the configured URL mappings

  • Important: The other URL bindings are required for API requests to Rivet.
  • More regions can be added by updating the rivet.yaml file and adding a new URL mapping in the config. Note that this will not be required once this support request is resolved; you will only need one URL mapping for lobby connections: /ws/{region}/{lobby} -> {lobby}.lobby.{region}.rivet.run

Playing Asteroids

Finally, you can follow the guide here on getting the activity running in Discord.

Screenshot of the Rivet Asteroids demo