Heavily based on Learning Go by examples by Aurélie Vache article series on Dev.to.
Please check Tinygo package compatibility before importing different packages
This simple app/game run on Game Boy Advance portable console and:
- display a screen with "Gopher" text and "Press START button"
- display two gophers
- When you press START button: your Gopher player just appear
- With multi directionnal arrows you can move your Gopher at left, right, top or bottom
- When you press A button: your Gopher jump :-D
- When you press SELECT button, you go back to "Start" screen
Install Go in 1.16 version minimum.
Brew:
brew install go-task
brew install tinygo
brew install mgba
task run
Note: time
does not work: https://remyhax.xyz/posts/gba-blog/ tinygo-org/tinygo#1578
task build
Let's run our app on mGBA emulator:
task mgba
Controls are configurable in the settings menu of mGBA. Many game controllers should be automatically mapped by default. The default keyboard controls are as follows:
A: X
B: Z
L: A
R: S
Start: Enter
Select: Backspace
- I've refactored some of the functions
- Improved the speed of the Gopher movement by implementing the redrawing the gopher
- Added a check if the gopher is within the display frame
- Added a Game Kill Screen :)
- Added a score that is calculated based on number of interrupts passed
- Added wind to generate random movement, I think now we can call it a game
Note: sometimes the game randomly crashes :)
If you get the following error:
MacBook-Air tiny-gba % task build
task: [build] GOFLAGS=-mod=mod tinygo build -size short -o bin/gopher.gba -target=gameboy-advance .
/opt/homebrew/bin/tinygo: line 2: /opt/homebrew/Cellar/tinygo/0.27.0/libexec/tinygo: Bad CPU type in executable
/opt/homebrew/bin/tinygo: line 2: /opt/homebrew/Cellar/tinygo/0.27.0/libexec/tinygo: Undefined error: 0
task: Failed to run task "build": exit status 1
Do this:
softwareupdate --install-rosetta
GOFLAGS=-mod=mod arch -x86_64 tinygo build -size short -o bin/gopher.gba -target=gameboy-advance .
It seems that Mac OS will remember to run this binary in x86 mode. You can now use the regular task build
, no need to modify the Taskfile.yml