GoTris 
       =======
       
       
       
       
 (IMG) GoTris (.png) 
       
       Introduction 
       -------------
       
       
       The famous block game written in Go compiled to WASM . This is significant because this implies that you can run Go programs in the browser. 
       
 (HTM) Go 
 (HTM) WASM 
       
       It is a quick port from TypeTris . 
       
 (DIR) TypeTris
       
       Play it!  Main source code  Download ZIP 
       
 (DIR) Play it!
 (DIR) Main source code
 (DIR) Download ZIP
       
       Controls 
       ---------
       
       
       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. 
       
       
       Build 
       ------
       
       
       Use build.sh to build it. 
       
 (DIR) build.sh
       
       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 apply 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 than 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. 
       
       - WASM  -
       
       
       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. 
       
 (DIR) browser.go
       - Golang package size  -
       
       
       The resulting WASM binary is ~1.5 MB (gzipped: 460 KB). I used these packages: 
       
       package  | size 
       log  | ~400 KB 
       math/rand  | ~20 KB 
       time  | ? KB (to be measured) 
       
       I omitted the log file from the production version so it saves some bytes. Omitting the math/rand 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? 
       
 (HTM) TinyGo 
       
       Source code 
       ------------
       
       
       Source code 
       
 (DIR) Source code
 (DIR) previous Elmtris
       
 (DIR) next TypeTris
       
       
       Related 
       --------
       
 (DIR) SQL injection demo
 (TXT) /img/fallback.svg (.svg) 
 (DIR) [Talk] Tetris4life
 (TXT) Semi generic tetris logo inspired by the Elm logo (.svg) 
 (DIR) snor
 (TXT) Moustache (.svg) 
 (DIR) Faddy webserver
 (TXT) /img/fallback.svg (.svg) 
 (DIR) io.MultiWriter gotcha!
 (TXT) Goofy gopher (.svg) 
 (DIR) Running Go tests in VSCode with CGO
 (TXT) Goofy gopher (.svg) 
 (DIR) shakehands
 (IMG) shakehands (.png) 
 (DIR) Overriding methods in Golang
 (TXT) Goofy gopher (.svg) 
 (DIR) Tetris for Commodore 64
 (IMG) Tetris screenshot WIP (.png) 
 (DIR) Tetris inner loop MOS6510 / C=64
 (IMG) Tetris Block (.png)