Building a peer-to-peer multiplayer game with pub/sub
In October 2020, the author decided to create a multiplayer game using Ably's pub/sub real-time messaging infrastructure. The game, called Depict-It, is based on a peer-to-peer architecture where players send and receive messages directly without an intermediary server. This makes it easier to manage state changes in the game and allows for seamless synchronization between players' browsers. The game consists of several phases: dealing, drawing, captioning, and voting. Each phase has a completion condition that triggers the next phase when met. Messages are sent on an Ably channel with both a "kind" and a "value", allowing the code to process them differently based on their content. The game's user interface is built using Vue.js, which enables the author to split different game phases into separate components and handle events such as click handlers. The UI also checks each game phase in the state and shows the correct UI elements accordingly. There are many potential improvements and extensions for the game, including adding more features or splitting players into separate games if there are too many. The author encourages others to contribute to the project by making a pull request or forking it to create their own version.
Company
Ably
Date published
Oct. 15, 2020
Author(s)
Jo Franchetti
Word count
1730
Language
English
Hacker News points
None found.