Anup Narkhede
📔  a journal

Paintball

For the past few weeks, I’ve been writing a multi-player game using Ruby on Rails. I’ve deliberately chosen to stick to Rails defaults and avoided using any external dependencies (apart from Redis to support Turbo Streams). Does it sound like I’m taking it too far? Yep, that’s precisely what I am trying to do here.

The first attempt is surprisingly encouraging, as you see in the video below.

What’s happening here?

00:00 - 00:05 As the players join, they start appearing as active in the right section. This is handled using a Turbo Stream that updates when a player status changes from invited to active.

00:05 - 00:42 The players move across the 8x8 grid using arrow keys and simultaneously shoot other players using a mouse click. The aim is to kill all your opponents and be the last survivor.

Behind the scenes, these movements and click user events are streamed to an action cable connection tied to a game engine. The game engine detects an event, re-calculates the player positions/scores and broadcasts an updated ‘world state’ to all subscribers. The channel subscriber javascript method detects this updated state and re-render the UI.

00:43 Once the game engine detects a lone survivor, they are declared a winner. Again, that’s a Turbo Stream update triggered by a change in the game state.

I aim to host it on a reliable server in the coming weeks, but stay tuned for updates until then!