Made a wooden fish mini game
When i was learning about the audio package of Ebitengine, just noticed that the sound file sounded like a woodfish. So I opened Aseprite and drew a simple animation immediately. Press the keyboard at the right time to play the sound according to the animation frames, which is like some kind of rhythm game. Feel funny, so I decided to make it real.
Requirements
There should be three modes:
- Manual Mode: play animations and sounds manually
- Auto Mode: autoplay animations and sounds
- Rhythm Mode: play sound according to the animation frame
And a simple UI framework is needed, with kind of text and menu widgets.
User Interface
For UI, the core idea is, every element will take a rectangle area on screen, so it has a func SetBounds(r image.Rectangle)
method to update its size and position. Also, most elements are very flex, its size and position depends on parent elements. So there will be a Layout()
to let all elements find its size and position.
It’s a tree, the root ask branches, what is your size. Branches know nothing, so it ask leaves. Leaves know things, then branches, then root, all of they know that now. Again, root tell branches, you’re here, that’s your bounds, and branches do same things. It’s similar flow for HandleInput() and FocusNext().
The UI should support navigation between pages, e.g. going to settings page from main title. The root node given to Ebitengine never changes, it handle navigation tasks. New page is loading at background, and be replaced once fully loaded. Transition animation starts and so on, that will be another topic.
One idea is, to keep it simple, very most of elements never need padding and borders. So, two new containers are maded to support padding and borders, in case any element need that.
Langauges and Themes
The game support Chinese and English only, but it’s true language switching. There’re not much text to translate, so Golang’s message package is totally enough for me.
And there’s a trick, it will certainly go to another new different page (here is the previous settings page), once language changed. All elements are fully recreated, so nothing need a manual update, which make it very simple. Theme and animation switching are totally same way too.
Save file and loading contents
The save file are acturally a json string, the only different is that it written to file on Windows, but to localStorage on Web. Thanks to Golang’s _js.go
naming, I can rewrite the function in the file, and keep all other parts not changed.
To load read theme files from outside are very similar, on Web it read and parse HTML codes to find theme file names, then read files by http request, and on Windows that’s still simple folder and files.
DEMO and codes
A Web demo is hosted at itch.io, Windows executable files are available too. No Linux and macOS ones, but source code are at Github.
Source code: https://github.com/bin16/wooden-fish