15 Jun 2021 - by 'Maurits van der Schee'
It was already 7 years ago that I wrote Minesweeper for a the iPad on the iPad (using Pythonista). It was an implementation of Minesweeper in Python and it was optimized for touch usage. I have ported that implementation to Go using the Ebiten game engine, which can compile to Web Assembly. This project really was like a code kata and it proofed to be a great learning experience and a lot of fun to build.
Unlike what I expected, the Ebiten engine does not have the object oriented concepts like Sprite, Layer and Scene that I was familiar with from Pythonista, Flash, Flex and the like. Instead it provides just the method "DrawImage" that can draw onto the canvas. This makes it harder to organize your screens and graphics. I decided that I didn't want a tight integration between the game logic and the drawing logic, so I decided to implement those concepts myself. This was quiet some work, but it simplified porting the code from Pythonista to Ebiten and as a bonus it may come in handy in a next port (if I will do another).
Next I had to test for performance and I've found that performance was good, but not super. Especially when running full screen on a full-HD screen with a low power CPU/GPU you could visibly see the dropped frames (not achieving 30 fps). Games with more moving elements on the screen benefit more from the (direct) drawing method than a game like minesweeper. When running the game on a lower resolution, for instance the WASM build in a small iframe the performance was perfect. This allows for replacement of Flash games with Ebiten games (although the WASM binary is 7 megabytes, which is quite large for a simple game like minesweeper).