Minimal C-lang library for creating classic arcade-like mini-games running on devices and browsers. Re-implemented version of crisp-game-lib for smaller devices.
- Playdate (Experimental)
-
Copy game_Template.c to
game[your game name].c
-
Comment out other games in menuGameList.c and add
void addGame[your game name]();
andaddGame[your game name]()
...(snip)... void addGameReflector(); void addGame[your game name](); void addGames() { /*addGameThunder(); ...(snip)... addGameReflector();*/ addGame[your game name](); }
-
Write your own game in
game[your game name].c
and renamevoid addGame_Template() {
tovoid addGame[your game name]() {
-
Build for browser and debug
-
Once the game is complete, revert other games that were commented out in menuGameList.c and build it for other devices
-
Install LovyanGFX library
-
Create
cglp[target device]/
directory (e.g.cglpM5StickCPlus/
) -
Copy
cglp[target device].ino
, ./src/lib/* and ./src/games/* files to the directory- cglpM5StickCPlus.ino
- cglpM5Stack.ino (ported by OBONO)
- cglpPyBadge.ino
-
Verify and upload
cglp[target device].ino
with Arduino IDE
Note: Tested on Windows simulator only.
-
Copy ./src/cglpPlaydate directory
-
Create
cglpPlaydate/build
directory -
Move to
cglpPlaydate/build
directory andcmake ..
-
Open
crisp-game-lib-portable.sln
with Visual Studio -
Build the solution (see Building for the Simulator using Visual Studio)
Note: Some features are limited due to device resource limitations.
- crisp-game-lib-arduboy (ported by OBONO)
- cglp-dentaroUI (ported by dentaro)
- cglpESPboy (ported by ESPboy)
-
Install Emscripten
-
Run
dev
npm script to start the dev server and watch js files -
Run
dev_c
npm script to watch c files and build wasm files
- Hold down the A button and press the B button (M5StickCPlus, M5Stack)
- Press the SELECT button (PyBadge)
- Press A, B, Up and Right buttons simultaneously (Playdate)
- Press the X key while holding down the up and down arrow keys (Browser)
- Press the B button (M5StickCPlus)
- Press the C Button (M5Stack)
- Press the START button (PyBadge)
- Press the Z key while holding down the up and down arrow keys (Browser)
- (A) X key, (B) Z key, (left/right/up/down) arrow keys
The source codes for library and games are written device-independent. Besides, you need to implement device-dependent code for the following functions:
-
Device initialization function (e.g.
setup()
in Arduino) that callsinitGame()
-
Frame update function (e.g.
loop()
in Arduino) that callssetButtonState()
andupdateFrame()
- The state of the button press must be notified to the library with the
setButtonState()
- The state of the button press must be notified to the library with the
-
Drawing and audio processing functions that are defined in machineDependent.h
md_getAudioTime()
function should return the audio timer value in secondsmd_playTone(float freq, float duration, float when)
function should play a tone withfreq
frequency,duration
length (in seconds) and staring fromwhen
seconds on the audio timermd_drawCharacter(unsigned char grid[CHARACTER_HEIGHT][CHARACTER_WIDTH][3], float x, float y, int hash)
function should draw the pixel art defined bygrid[y][x][r, g, b]
at position (x, y). Sincehash
will be the same for the same pixel art, you can cache pixel art images usinghash
as an index and avoid redrawing the same image
Sample device-dependent codes are cglpM5StickCPlus.ino and cglpPyBadge.ino.