Go, WASM, Conway

Table of Contents

If you didn’t know about Conway’s Game of Life, you’re one of today’s lucky 10000.

It is a simple game, played on a grid with cells that are either live or dead, and updates at a certain interval with the following rules:

  1. Any live cell with fewer than two live neighbors dies, as if by underpopulation.
  2. Any live cell with two or three live neighbors lives on to the next generation.
  3. Any live cell with more than three live neighbors dies, as if by overpopulation.
  4. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

I wanted to experiment with WASM and gamedev in Golang, so I put together a quick PoC using Ebitengine. You can look at the code in this repository, and below I embeded the result.

Here are the controls:

Action Mouse/Keyboard Mobile
Place Live Cell Left Click Tap/Slide
Remove Live Cell Right Click -
Start/Pause Space Two Finger Tap
Change Speed TAB Two Finger Swipe Right
Reset Board ESC Three Finger Tap

Try it out:

I also made this demo to test out mobile gestures, it handles:

  • tapping (one, two and three fingers)
  • two finger panning (swipe) in 4 directions
  • two finger pinching in and out

Try it out in your phone:

Have fun!

EDIT:

I moved the code that handles the touch events into a separate package. Feel free to check it out.