apps / games
I build mobile web games with Go engines compiled to WebAssembly (WASM):
- Duck Duck Bay is a puzzle game about building a food chain.
- Launchpad is a vertical platformer with a rocket and breakable platforms.
- Marshfall is a bubble shooter with matching clusters and a rising tide.
I keep the game rules in Go. JavaScript handles browser input and rendering.
Go in the browser
The browser runs the game engine locally. A move does not need an HTTP request to calculate its result.
I compile the browser entry point with Go's WebAssembly target:
GOOS=js GOARCH=wasm go build -o web/game.wasm ./cmd/game
cp "$(go env GOROOT)/lib/wasm/wasm_exec.js" web/
wasm_exec.js connects the Go runtime to the browser. I copy it from the same Go toolchain that builds the WASM file.
The game package contains the rules. A separate js && wasm entry point connects that package to JavaScript through syscall/js.
Duck Duck Bay exposes functions for starting a game and applying player actions. Marshfall exposes functions for aiming and firing.
Both expose getState, which returns a JSON string. JavaScript reads the state and renders it.
This split lets ordinary Go tests exercise the game rules without a browser.
State and rendering
Go owns the board and decides what each action changes. JavaScript presents those changes with HTML, CSS, and browser APIs.
In Duck Duck Bay, the same Go species data supplies the rules and the food chain guide.
In Launchpad, Go calculates rocket motion and emits sound events. JavaScript turns those events into sound with the Web Audio API.
In Marshfall, Go calculates a shot's landing cell when the player fires. JavaScript animates the shot toward that result.
I keep those decisions in the engine so the displayed result follows the game rules.
Time and replay
A turn-based game and a moving game need different clocks.
Duck Duck Bay advances through player actions. Its seeded random generator makes those actions reproducible from the same starting state.
Launchpad uses a fixed 60-tick-per-second simulation. JavaScript accumulates elapsed time and runs the required ticks before rendering.
A faster display can render more frames without changing the physics rate. The loop caps a long pause before it adds elapsed time.
Marshfall also needs elapsed time because its tide rises while the player aims. A replay needs the seed and timed inputs.
A seed alone does not record a complete game.
Game-specific rules
Each engine uses ordinary Go data structures for its rules.
Duck Duck Bay combines a board with species data. Plants attract herbivores, and herbivores attract predators.
Launchpad updates position and velocity. A normal platform breaks on its second bounce, while a boost platform adds more upward force.
Marshfall uses a staggered grid. After a shot attaches, the engine searches adjacent cells for a matching cluster.
A second search starts at the ceiling. Bubbles outside that connected group fall.
This excerpt shows the order of those operations:
cluster := g.sameTypeCluster(row, col)
if len(cluster) >= 3 {
g.PoppedBubbles = g.clearCells(cluster)
}
fallen = g.captureDetachedBubbles()
Delivery
The browser loads the WASM file with the page's JavaScript and CSS. The game engine needs no Node runtime.
Duck Duck Bay and Marshfall embed these assets in a Go HTTP server. Their servers run as uni guests.
Fingerprinted asset URLs let the browser cache the large WASM download. A changed asset gets a different URL.
Duck Duck Bay also checks the server's game version before starting a new game. It reloads the page when the versions differ.
I keep the engine in Go and the browser code close to the browser APIs.