This is a 2D/3D game engine for MicroPython. Core engine features are written in C and integrated into MicroPython as external C modules. The engine API is exposed through Python modules.
- Node API with hierarchy format (parent/child) to render rectangles, circles, lines, text, GUI buttons, sprites, and 3D meshes.
- All nodes can be rotated and scaled
- Resource API for loading and holding data like 1/4/8/16-bit bitmap textures, .wav sound files, RTTTL ringtone tracks, fonts, and 2D/3D noise
- Basic button API
- Audio API for 4 audio channels to play .wav, RTTTL, or tones
- Basic 2D physics engine with rotated rectangle and circle colliders exposed as nodes
- Math API for
Vector2
andVector3
types - Tween/animation API to animate attributes of nodes
- Saves API for reading and writing certain common types of data
- Time API for utilizing hardware real-time-clock (RTC) for keeping persistent time across device power-downs
- Link API for connecting two devices together to make local multiplayer games
You can also read the engine documentation, visit the arcade to download games, or make your own games using the Code Editor Web App:
The engine can run on most platforms that run MicroPython. However, some drivers may need to be implemented for buttons, screen, and audio.
The engine has been tested on and ported to the following platforms:
- Linux/Unix
- RP2350 with 16MiB flash
- Webassembly
- Update package list:
sudo apt update
- Install build chain dependencies (https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf#page=33):
sudo apt install git python3 cmake gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential g++ libstdc++-arm-none-eabi-newlib
- Clone TinyCircuits MicroPython:
git https://github.com/TinyCircuits/micropython.git mp-thumby
cd
into MicroPython:cd mp-thumby
- Checkout engine branch:
git checkout engine
- Init the engine submodule:
git submodule update --init --recursive
- Setup cross compiler:
- cd
mpy-cross
(folder is insidemp-thumby
) make -j8
- cd
- Go back to MicroPython root folder:
cd ..
- Setup
rp2
port:cd ports/rp2
make submodules
make clean
- Go back to MicroPython root folder:
cd ../..
- Go into engine folder:
cd TinyCircuits-Tiny-Game-Engine
- Run the custom Python build and upload script:
python3 build_and_upload.py
(NOTE: you may need to install pyserial
: python3 -m pip install pyserial
and the .uf2 will be output to mp-thumby/ports/rp2/build-THUMBY_COLOR/firmware.uf2
once you see the message Finding drive letter...
)
These instructions assume that you are cloning MicroPython from the TinyCircuits Fork that has been pre-modified
- Install SDL2:
sudo apt install libsdl2-dev
- Install FFI:
sudo apt install libffi-dev
- Install build tools:
sudo apt install build-essential
- Clone TinyCircuits MicroPython:
git clone https://github.com/TinyCircuits/micropython.git mp-thumby
cd
into MicroPython:cd mp-thumby
- Checkout engine branch:
git checkout engine
- Init the engine submodule:
git submodule update --init --recursive
- Setup UNIX port:
cd ports/unix
make submodules
cd
to engine file system to build and run MicroPython and the enginecd
:cd ../../TinyCircuits-Tiny-Game-Engine/filesystem
- build:
(cd ../../ports/unix && make -j8 USER_C_MODULES=../../TinyCircuits-Tiny-Game-Engine DEBUG=1)
- run:
../micropython_loop ../../ports/unix/build-standard/micropython -X heapsize=2617152 main.py
Use (cd ../../ports/unix && make clean)
to make clean if needed
If you followed the one of two methods to setup everythign above, you can run the following from micropython/TinyCircuits-Tiny-Game-Engine/filesystem
to build and run a MicroPython script on Linux quickly:
(cd ../../ports/unix && make -j8 DEBUG=1 USER_C_MODULES=../../TinyCircuits-Tiny-Game-Engine) && (../../ports/unix/build-standard/micropython main.py)
If a hard fault blue screen occurs on the device, it will also usually occur in the Linux build too. It likely still won't be easy to solve, but you can see exactly where in MicroPython or the engine C code where the fault occurs using gdb
. Using Linux is easier, but gdb
can be used with the device as well but it is harder to setup.
Refer to the above section where MicroPython and the engine are built on Linux for Linux. Make sure the DEBUG=1
flag is added to the make
command as shown above and then run MicroPython using gdb
like so:
- Navigate filesystem:
cd TinyCircuits-Tiny-Game-Engine/filesystem
- Build and run with
gdb
:(cd ../../ports/unix && make -j8 DEBUG=1 USER_C_MODULES=../../TinyCircuits-Tiny-Game-Engine) && (gdb ../../ports/unix/build-standard/micropython main.py)
- In the
gdb
prompt, executerun main.py
and do it again after launching game when the window closes - Play the game until it crashes and see the line in the C code where the fault occurred. In the
gdb
prompt, executebt
to see a stacktrace for the steps up to this point
The above steps will get you started, you will likely need to understand the code and use other gdb
tools to investigate the issue. For example, to see the value of a memory address, use x <hex address>
in the gdb
prompt.
- Follow instructions here https://emscripten.org/docs/getting_started/downloads.html and finish after executing
source ./emsdk_env.sh
(will need to execute this last command inemsdk
in every new terminal/session) git clone https://github.com/TinyCircuits/micropython/tree/engine micropython
cd micropython/ports/webassembly
make -j8 USER_C_MODULES=../../TinyCircuits-Tiny-Game-Engine
To mimic the hardware, the heap needs to be 520kB
SRAM + 2MiB
of FLASH scratch = 520*1000 + 2*1024*1024 = 2617152
Make sure to check that the copied structures in src/utility/engine_mp.h are still the same in the version of MicroPython you're updating to. Some structures are not exposed so they had to be copied to where the engine can use them.
- Download and compile https://github.com/raspberrypi/picotool (requires pico-sdk be installed in default known location or pass
-DPICO_SDK_PATH=
tocmake
) - Upload a firmware and all files that should be included to Thumby Color (run the
collect_files_for_image.py
and copy files using Thonny from theproduction_files/tree
folder) - Connect Thumby Color to computer with picotool installed in and the device in BOOTSEL mode (turn off, press and hold down DPAD direction, turn back on)
- Run:
sudo ./picotool save -r 0x10000000 0x11000000 thumby_color_full_image_00_00_0000.bin
(saves fromXIP_BASE
to16MiB
s after to bin file) - Run:
sudo ./picotool uf2 convert thumby_color_full_image_00_00_0000.bin thumby_color_full_image_00_00_0000.uf2