![]() |
CHGame 0.3.0
Libraries for the CHGame handheld
|
Effects: motion maths, the screen shake, and (chgame/Sizzle.h) particles, banners and floating texts. More...
Enumerations | |
| enum | Ease : uint8_t { LINEAR , OUT_CUBIC , OUT_BACK , IN_OUT , OUT_BOUNCE } |
| Easing curves for ease(). More... | |
| enum | Kind : uint8_t { SPARK , CONFETTI , STAR , DUST } |
| The particle kinds (the game's switches decide which exist). More... | |
| enum | BannerStyle : uint8_t { B_RAINBOW , B_GOLD , B_RED , B_CYAN , B_WHITE } |
| Banner colour styles (the game's SIZZLE_STYLES decide which exist). More... | |
Functions | |
| int | easeCurve (const int16_t *curve, int t, int n) |
| Ease through a curve table. | |
| int | ease (Ease e, int t, int n) |
| Ease: progress through a curve. | |
| int | bounce (int t, int n) |
| The OUT_BOUNCE curve. | |
| int | isin (int a) |
| Integer sine. | |
| int | icos (int a) |
| Integer cosine. | |
| uint32_t | rnd () |
| A random number for presentation (xorshift32). | |
| int | rndRange (int lo, int hi) |
| A random number in a range, for presentation. | |
| void | reseed () |
| Restart rnd() from its fixed seed. | |
| void | shake (uint8_t frames, uint8_t amplitude) |
| Start a screen shake. | |
| bool | shaking () |
| Whether a shake is running. | |
| void | applyShake (int y0, int y1, int fill=-1) |
| Shake the finished framebuffer: call after drawing, before the flush. | |
| void | shakeTick () |
| Count the shake down one tick: once per logic tick. | |
| void | shakeStop () |
| Stop the shake at once. | |
| void | spawn (Kind k, int x, int y, int vx16, int vy16, uint8_t life, uint8_t colour) |
| Launch one particle. | |
| void | burst (Kind k, int x, int y, uint8_t n, int speed16, uint8_t colour) |
| A radial burst: n particles flying out from a point. | |
| void | fountain (int x, int y, uint8_t n) |
| A fountain of confetti thrown up from a point (a win). | |
| bool | particles () |
| Whether any particle is still flying. | |
| bool | particlesAlive () |
| The same as particles(). | |
| void | banner (const char *text, BannerStyle s, int cy, uint8_t frames=70) |
| Show a banner: big centred lettering with an outline that pops in, holds, and blinks out ("BLACKJACK!", "YOU WIN"). | |
| void | holdBanner (bool on) |
| Keep the banner up (before it blinks out) until let go. | |
| bool | bannerActive () |
| Whether a banner is showing. | |
| void | floatText (const char *text, int x, int y, uint8_t colour) |
| A floating text ("+$15") that rises from a point and fades out. | |
| void | drawFloats () |
| Draw the floating texts: while drawing, on top of the scene. | |
| bool | activeRows (int &lo, int &hi) |
| The band of rows everything transient covers (particles, floats, banner, shake): what a partial redraw must include. | |
| void | clear () |
| Remove every particle, float and the banner at once (and stop a shake). | |
| void | update () |
| Move everything on by one tick: once per logic tick. | |
| void | drawParticles (uint8_t dust=2) |
| Draw the particles: while drawing, on top of the scene. | |
| void | drawBanner () |
| Draw the banner, if one is showing: while drawing, last. | |
Variables | |
| const int16_t | EASE_CUBIC [17] |
| The curves' tables (17 points, 0..256), for easeCurve(). | |
Effects: motion maths, the screen shake, and (chgame/Sizzle.h) particles, banners and floating texts.
| enum fx::Ease : uint8_t |
Easing curves for ease().
Each curve is a 17-point table; ease() is inline, so a call with a constant curve links only that curve's table.
| enum fx::Kind : uint8_t |
The particle kinds (the game's switches decide which exist).
| enum fx::BannerStyle : uint8_t |
| int fx::easeCurve | ( | const int16_t * | curve, |
| int | t, | ||
| int | n | ||
| ) |
Ease through a curve table.
| curve | A 17-point table (EASE_CUBIC ...), or nullptr for linear. |
| t | Time, 0..n. |
| n | Duration. |
|
inline |
Ease: progress through a curve.
| e | Which curve. |
| t | Time, 0..n (clamped). |
| n | Duration (frames, for instance). |
|
inline |
The OUT_BOUNCE curve.
| t | Time, 0..n. |
| n | Duration. |
| int fx::isin | ( | int | a | ) |
Integer sine.
| a | Angle in 1/256 turns (any value: it wraps). |
|
inline |
Integer cosine.
| a | Angle in 1/256 turns. |
| uint32_t fx::rnd | ( | ) |
A random number for presentation (xorshift32).
Presentation-only randomness: sparkle, confetti, shake. It never touches game outcomes (those use the game's own generator), and reseed() restarts it so scripted runs repeat.
| int fx::rndRange | ( | int | lo, |
| int | hi | ||
| ) |
A random number in a range, for presentation.
| lo | The smallest value. |
| hi | One past the largest value. |
| void fx::reseed | ( | ) |
Restart rnd() from its fixed seed.
| void fx::shake | ( | uint8_t | frames, |
| uint8_t | amplitude | ||
| ) |
Start a screen shake.
shake() starts it; applyShake() moves the finished frame and shakeTick() counts it down once per logic tick.
| frames | How many ticks it lasts. |
| amplitude | The vertical jolt in pixels at 10 ticks left; it scales with the ticks left, so the shake dies away (at least 1 px). It also moves 2 px sideways. |
| bool fx::shaking | ( | ) |
Whether a shake is running.
| void fx::applyShake | ( | int | y0, |
| int | y1, | ||
| int | fill = -1 |
||
| ) |
Shake the finished framebuffer: call after drawing, before the flush.
| y0,y1 | The band of rows to move (inclusive). |
| fill | < 0 (default): rows the move uncovers keep their pixels, shifted in place; else they are filled with this colour. |
| void fx::shakeTick | ( | ) |
Count the shake down one tick: once per logic tick.
| void fx::shakeStop | ( | ) |
Stop the shake at once.
| void fx::spawn | ( | Kind | k, |
| int | x, | ||
| int | y, | ||
| int | vx16, | ||
| int | vy16, | ||
| uint8_t | life, | ||
| uint8_t | colour | ||
| ) |
Launch one particle.
When the pool is full it takes a random one's place.
| k | Its kind. |
| x,y | Where it starts, in pixels. |
| vx16 | Horizontal speed in 1/16 px per tick (-127..127). |
| vy16 | Vertical speed in 1/16 px per tick (-127..127; negative is up). |
| life | How many ticks it lives. |
| colour | Its colour. |
| void fx::burst | ( | Kind | k, |
| int | x, | ||
| int | y, | ||
| uint8_t | n, | ||
| int | speed16, | ||
| uint8_t | colour | ||
| ) |
A radial burst: n particles flying out from a point.
| k | Their kind. |
| x,y | The centre. |
| n | How many. |
| speed16 | Top speed in 1/16 px per tick (each gets half to all of it). |
| colour | Their colour. |
| void fx::fountain | ( | int | x, |
| int | y, | ||
| uint8_t | n | ||
| ) |
A fountain of confetti thrown up from a point (a win).
| x,y | Where it springs from. |
| n | How many pieces. |
| bool fx::particles | ( | ) |
Whether any particle is still flying.
|
inline |
The same as particles().
| void fx::banner | ( | const char * | text, |
| BannerStyle | s, | ||
| int | cy, | ||
| uint8_t | frames = 70 |
||
| ) |
Show a banner: big centred lettering with an outline that pops in, holds, and blinks out ("BLACKJACK!", "YOU WIN").
| text | The text (copied; at most SIZZLE_BANNER_CHARS - 1 characters). |
| s | Its style. |
| cy | The row its centre sits on. |
| frames | How many ticks it stays up, blinking out at the end (default 70). |
One banner at a time: a new one replaces the last.
| void fx::holdBanner | ( | bool | on | ) |
Keep the banner up (before it blinks out) until let go.
| on | true to hold it; false to let it blink out. |
| bool fx::bannerActive | ( | ) |
Whether a banner is showing.
| void fx::floatText | ( | const char * | text, |
| int | x, | ||
| int | y, | ||
| uint8_t | colour | ||
| ) |
A floating text ("+$15") that rises from a point and fades out.
| text | The text (copied; at most SIZZLE_FLOAT_CHARS - 1 characters). |
| x,y | Where it starts. |
| colour | Its colour. |
Several can be up at once; a new one takes the first free slot (or the first slot when all four are busy). Each lives 50 ticks.
| void fx::drawFloats | ( | ) |
Draw the floating texts: while drawing, on top of the scene.
| bool fx::activeRows | ( | int & | lo, |
| int & | hi | ||
| ) |
The band of rows everything transient covers (particles, floats, banner, shake): what a partial redraw must include.
| lo | Gets the top row. |
| hi | Gets the bottom row. |
| void fx::clear | ( | ) |
Remove every particle, float and the banner at once (and stop a shake).
| void fx::update | ( | ) |
Move everything on by one tick: once per logic tick.
| void fx::drawParticles | ( | uint8_t | dust = 2 | ) |
Draw the particles: while drawing, on top of the scene.
| dust | The size of a DUST puff in pixels (default 2). |
| void fx::drawBanner | ( | ) |
Draw the banner, if one is showing: while drawing, last.
|
extern |
The curves' tables (17 points, 0..256), for easeCurve().