RCWeb Snake

Snake is an early RCWeb asymmetric prototype that turns one shared display into a multiplayer snake board while phones act as directional pads. It is useful both as a playable experiment and as a developer-facing example of the older RCWeb style where controllers call explicit viewer methods and the viewer pushes targeted JavaScript back to specific controllers.

Icon

icon

Screenshot

screenshot

The Prototype

On the screen, Snake is straightforward: multiple snakes share one grid, compete for the same fruit, grow when they eat, and crash if they hit another body or their own. When a snake dies, its score resets and it waits through a respawn countdown before re-entering the board.

What makes this prototype interesting for RCWeb developers is the way it coordinates per-player state without any backend game session model beyond the RCWeb room. Each phone becomes a player purely by sending its rc.client id to the viewer. The viewer builds that snake entity locally, keeps all authoritative game state on the display, and targets score or respawn updates back to the correct controller.

RCWeb Communications

Snake uses the classic early asymmetric RCWeb pattern:

  • /snake/ is the authoritative viewer.
  • /snake-control/ is the lightweight controller.
  • The viewer redirects all other clients in the room into the controller app using rc.send(js, "!" + rc.client).

The communication surface is intentionally tiny:

  • The viewer exposes movement methods such as snakeGame.up(id), snakeGame.down(id), snakeGame.left(id), and snakeGame.right(id).
  • Controllers send raw JavaScript strings like rc.send("snakeGame.up('" + rc.client + "');", "snake").
  • The controller's rc.client value becomes the snake id on the viewer.

The viewer then sends targeted updates back to the controller app, again using plain JavaScript strings:

  • window.updateScore(score) for score changes
  • window.updateColor(hue) when a snake is first assigned a color
  • window.startCountdown(seconds) after a crash

Those messages are scoped to the correct phone by checking rc.client inside the outbound code before invoking the controller-side function.

Why It Matters

For someone writing a new RCWeb game, Snake is a clean example of the communication fundamentals:

  1. The display owns the board, collisions, fruit placement, and respawn logic.
  2. Controllers only send directional intent.
  3. Player identity is derived directly from rc.client.
  4. The viewer targets feedback back to exactly one controller when needed.
  5. No REST API, backend schema, or separate session service is required.

This prototype is especially helpful if you want to understand the "raw" RCWeb model before adopting later conveniences like richer snapshots or more structured controller state. It shows how little code is actually required to build a working asymmetric multiplayer app when the room, client ids, and remote JavaScript dispatch are already provided by RCWeb.

DocumentationServer TelemetryServer StatsServer HTTP LogServer WebSocket Log