“A language a year keeps the doc away!”
The famous block game written in Go compiled to WASM. It is a quick port from TypeTris.
Play it! Main source code Download ZIP
Use cursor keys ▲ ▶ ▼ ◀ SPACE or I J K L M SPACE to control the game.
You need a recent version of Chrome, Firefox, (non-legacy) Edge or Safari to play it.
Use build.sh to build it.
Go version 1.14 is needed because
of WASM support. Although
syscall/js is available from 1.11 on.
However the backward compatibility promise does not applies to this package
(fortunately, because there was some major simplification between 1.11 and 1.14).
This implies that the code may be broken in versions other then 1.14. I try
to keep this up-to-date.
What did I learn?
I learned to love channels again!
Debugging was - due to the absence of tools - not a breeze, but the good thing is that the Golang logger logs to the browser console and in case of errors full stack traces are available in the console too.
Also this was my first real WASM project. To make this portable I abstracted the renderer (browser.go) and it is desired to do this for the keyboard handler too.
Golang package size
The resulting WASM binary is ~1.5 MB (gzipped: 460 KB). I used these packages:
|time||? KB (to be measured)|
I omitted the log file from the production version so it saves some bytes. Omitting the
packages was not worth it. If you really want you can use something like
date.Nanoseconds % len(blocks)
to get a random block. Maybe give TinyGo a go for a smaller WASM file?
|blocks.go||Golang||13 March||1.6 KB||Download View|
|browser.go||Golang||16 March||2.5 KB||Download View|
|build.sh||Shell script||15 March||178 Bytes||Download View|
|gotris-big.png||PNG image||16 March||12.1 KB||Download View|
|gotris-small.png||PNG image||13 March||6.0 KB||Download View|
|gotris.css||Stylesheet||19 March||103 Bytes||Download View|
|gotris.go||Golang||16 March||4.6 KB||Download View|
|gotris.html||HTML||19 March||468 Bytes||Download View|
|gotris.png||PNG image||16 March||12.1 KB||Download View|
|gotris.wasm||WASM binary||16 March||1.5 MB||Download View|
|gotris.zip||Zip archive||16 March||474.4 KB||Download View|
|render.go||Golang||16 March||180 Bytes||Download View|
|tetris.css||Stylesheet||Oct ’17||2.8 KB||Download View|
|15 files||2.0 MB|