CHGame 0.3.0
Libraries for the CHGame handheld
Loading...
Searching...
No Matches
CHGame library

The one include for a CHGame game: buttons, frame pacing, palette, drawing, lettering, effects, sound, saving and the debug protocol. More...

Modules

 Buttons and frame pacing
 The global chgame object: the frame clock and the eight buttons.
 
 Palette
 The sixteen house colours and pal::: felt themes, fades, flashes and colour cycling.
 
 Drawing
 Panels, span sprites, dithering, polygons and the 3x5 font, drawn into CHGfx's framebuffer.
 
 Lettering masks
 Outlined, shadowed and gradient lettering, logos and the cover titles.
 
 Effects maths
 fx::: easing curves, integer sine and cosine, presentation randomness and the screen shake.
 
 Particles, banners and floating texts
 fx:: particles (sparks, confetti, coins ...), the pop-up banner and floating texts, configured per game.
 
 Sound and LED
 audio::: sound effects, music and the status LED.
 
 Saving
 save::: a game's options and progress in flash, with a CRC, kept across power cycles and re-uploads.
 
 Number formatting
 Integers, money and times as text, without printf.
 
 RAM functions
 RAMFUNC(name): put a hot function in SRAM, about three times faster than flash.
 
 Debug protocol
 dbg::: the serial protocol the simulator and the PC tools drive a game through.
 
 Build switches
 CHGAME_DEBUG and CHGAME_PROFILE: set them with build.extra_flags.
 

Detailed Description

The one include for a CHGame game: buttons, frame pacing, palette, drawing, lettering, effects, sound, saving and the debug protocol.

#include <CHGame.h>
The one include for a CHGame sketch.

brings everything the twenty casino games share, on top of CHGfx (the framebuffer, the panel and its DMA). It is modelled on the Arduboy2 library: one global object, chgame, with the same button names, nextFrame() and pollButtons(), and a handful of small namespaces for the rest (pal::, fx::, audio::, save::, dbg::).

Every CHGame game runs the same frame loop: logic, then gfx_wait() (the previous frame has finished going out to the panel), then drawing into the framebuffer, then gfx_flushAsync() (the panel gets it by DMA while the next frame's logic runs).

void setup() {
chgame.boot(); // buttons; START held 3 s goes back to the menu
gfx_begin(GFX_DIV2, GFX_12BPP); // the panel
pal::init(); // the house colours
}
void loop() {
dbg::poll(); // the debug protocol (nothing in a release build)
if (!chgame.nextFrame()) return;
// ... logic ...
gfx_wait(); // the previous frame has gone out: draw
// ... draw into the framebuffer ...
gfx_flushAsync(); // DMA to the panel while the next frame's logic runs
}
bool nextFrame()
Whether it is time for the next frame.
void pollButtons()
Take this frame's snapshot of the buttons.
void boot()
Set up the button pins (inputs with pull-ups) and take a first reading.
void setFrameRate(uint8_t fps)
Set the frame rate nextFrame() paces to.
CHGame chgame
The one instance: chgame.boot(), chgame.pressed() ...
@ FELT
3: the table felt; re-dyed by pal::setTheme().
Definition Palette.h:45
@ GFX_DIV2
HCLK/2 = 24 MHz: the fastest the chip can clock SPI, and the default.
Definition CHGfx.h:232
@ GFX_12BPP
ST7735 COLMOD 0x03, RGB444, 1.5 bytes/px -> 119 fps.
Definition CHGfx.h:220
void gfx_clear(uint8_t c)
Fills the clip rectangle (normally the whole screen) with one colour.
void gfx_flushAsync(void)
Starts sending the whole framebuffer and returns at once; the DMA interrupt does the rest.
void gfx_wait(void)
Waits until the flush in flight, if any, has finished.
static void gfx_begin(uint8_t spiDiv=GFX_DIV2, uint8_t colorMode=GFX_16BPP)
Starts the panel: pins, SPI1, DMA, a hardware reset and the ST7735 initialisation,...
Definition CHGfx.h:308
void update()
Run the LED patterns: once per logic tick.
void poll()
Read and answer commands: at the top of loop(), before nextFrame().
void tick()
Advance the colour cycling and any flash by one tick.
void commit()
Work out the final colours and hand them to CHGfx if any changed.
void init(const uint16_t *base=HOUSE)
Load a set of colours and commit them at once.

The whole of that sketch, with a sound and a saved counter, is the Hello example. The twenty games in the library's examples/Games/ folder are complete programs built on it.

See also
The library's README, Getting started (for Arduboy developers), Why the library is as it is