Examples are all well and good but the real fun starts with creating our own games and demos.
We've created a boilerplate template to make setting up a new C++ project super simple.
Download the boilerplate template into a new directory, to keep things tidy:
git clone https://github.com/pimoroni/picosystem-boilerplate.git ~/ourproject
cd ~/ourproject
(we're calling our directory ourproject
, but obviously you can replace ourproject
with name that describes your project better such as meowbestcatsimulator
!).
This newly cloned project directory will contain a few different files, but the ones you'll be primarily concerned with are:
CMakeLists.txt
contains instructions to the compiler and linker about how to build the project. You might need to change the options in here if you want to change the project name or set high level options like the PicoSystem resolution or turning the splash screen on or off.main.cpp
contains the source code for our project - this is where your game code will go and where the magic will happen!Open up main.cpp
in an editor (on a Pi, you can nano main.cpp
) and add in some simple code to draw on the screen.
#include "picosystem.hpp"
// this saves us having to prefix every picosystem call which makes the
// code a lot tidier and more readable..
//
// picosystem::text("this is a message", 10, 10);
//
// ..becomes...
//
// text("this is a message", 10, 10);
//
// \o/
using namespace picosystem;
void init() {
}
void update(uint32_t tick) {
}
void draw(uint32_t tick) {
pen(0, 0, 0);
clear();
pen(15, 15, 15);
text("Hello, world!", 0, 0);
}
Now we have our project ready we need to build it, this converts your code into something the machine can understand. We create a new directory for the project to be built in:
mkdir ~/ourproject/build
cd ~/ourproject/build
cmake ..
make
Once completed there will be a .uf2 file in your build
directory (by default it's called my_project.uf2
). Put your PicoSystem into DFU mode and copy it over.
There are a few options you can set in your project to change the behaviour of PicoSystem.
These can be set by adding one of the following lines in your CMakeLists.txt
:
pixel_double(NAME)
: set resolution to 120x120 for a retro chunky pixel aesthetic (and significant RAM saving)no_spritesheet(NAME)
: do not include the default sprite sheet (saves 32kB of RAM)no_font(NAME)
: do not include the default font (saves 1kB)disable_startup_logo(NAME)
: disables the PicoSystem startup logo animationno_overclock(NAME)
: disables overclocking of the RP2040 (by default we set it to 250MHz)In all cases NAME
should be the name you supplied to picosystem_executable()
.
If you need them, the build options are also available as compiler flags:
-DPIXEL_DOUBLE
: set resolution to 120x120 for a retro chunky pixel aesthetic (saves 84kB of RAM)-DNO_SPRITESHEET
: do not include the default sprite sheet (saves 32kB of RAM)-DNO_FONT
: do not include the default font (saves 1kB)-DNO_STARTUP_LOGO
: disables the PicoSystem startup logo animation-DNO_OVERCLOCK
: disables overclocking of the RP2040 (by default we set it to 250MHz)