A cart is made up of a few callbacks. You don't have to implement them all, but whatever you do implement will be called by the host. It's just a zip file, with main.wasm
in the root. Use functions from the null0 api to make your game.
Here is one, now:
All supported languages should have very simple/similar syntax.
You can find more examples here.
lifecycle
// called on load, you can also use main() in C
void load();
// called on every frame
void update();
// called when the cart is unloaded
void unload();
input
keys
Button input is mapped using libretro keys. If the event comes from a keyboard, player
is set to 9999
. I think it helps to imagine all controllers are an SNES controller for most input-purposes, then you can use buttonUp
/buttonDown
for any player.
- D-pad: ▲◀︎▶︎▼
- A: z
- B: x
- X: a
- Y: s
- L: q
- R: w
- SELECT: shift
- START: enter
Here is an input-demo, that shows how the keys work:
Here are the callbacks you can define:
// mapped controller callback
void buttonUp(GamepadButton button, unsigned int player);
// mapped controller callback
void buttonDown(GamepadButton button, unsigned int player);
// called when keys are unpressed
void keyUp(Key key);
// called when keys are pressed
void keyDown(Key key);
// called when mouse-button is pressed
void mouseDown(unsigned int button);
// called when mouse-button is released
void mouseUp(unsigned int button);
// called when mouse is moved
void mouseMoved(float x, float y);
distribution
To distribute your game to others, you can either save your cart as main.null0, alongside the native runtime (and name the runtime whatever you want) or you can embed it all in one executable:
# linux or mac
cat build/host/null0 build/carts/input_c.null0 > tester
# windows
copy /b build/host/null0.exe+build/carts/input_c.null0 tester.exe
This is very similar to how love2d works.