Multiplayer Games

Trace Game

As the web becomes a more collaborative place, apps are increasingly expected to have realtime features, and online gaming is certainly no exception. This can quickly become complicated, since games don't always fall into simple document, table, or key-value data formats, and trying to merge that data across peers can become troublesome. If merges aren't handled just right, game state can differ from each player, causing inconsistent user experience and gameplay bugs that are difficult to track down.

GUN handles the merge problems behind the scenes, and syncs your game state between the other players handling the merge for you, letting you focus on the game itself.

One of our published GUN apps is a realtime game with mechanics similar to Tron. Several different components of the game are synced between the clients and server, such as the waiting room, game board, and the player positions. Each player is rendered onto the screen from GUN's state, and when a player turns or collides, it puts an update into gunDB, which updates every players' state and their view. Adding an invincibility feature to the game was as easy as telling gun whether your player was invincible, adding a one-line exception to collision detection, and adding a color to invincible players. Now every player can see who not to mess with, and all in realtime.

Even though most of the fun happens on the clients, servers aren't left out of the picture. Since gun works the same on both browsers and servers alike, certain aspects are handled centrally, such as the waiting room, and inactive players. When a player joins, they push themselves to a list of waiting players. If a spot opens up in the game, the server chooses the next to take their place.

Connect 4

High speed games aren't the only games that benefit from real time data. Consider turn-based games: some parts of the game are slow moving, and some parts are fast (pondering a move for a while, or seeing a perfect opening and launching for it). Users don't want to wonder "Should I refresh? Are the turns actually updating?" by providing users with lightning-fast updates, they can focus on what really matters: the game.

We built a turn-based demo you can try based off Connect-4 (Wikipedia Connect 4). Try it with a coworker across the room, or friends in another state - the updates should happen at the speed of life.

Click here to play

If you want real time updates in your app, give gun a shot and let us know how it works for you!