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

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().
 

Detailed Description

Effects: motion maths, the screen shake, and (chgame/Sizzle.h) particles, banners and floating texts.

Enumeration Type Documentation

◆ Ease

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.

Enumerator
LINEAR 

Straight.

OUT_CUBIC 

Fast, then slowing to a stop.

OUT_BACK 

Overshoots the end, then settles back (goes past 256).

IN_OUT 

Slow, fast, slow.

OUT_BOUNCE 

Drops and bounces to a stop (overshoots).

◆ Kind

enum fx::Kind : uint8_t

The particle kinds (the game's switches decide which exist).

Enumerator
SPARK 

A pixel with a cross-shaped flash for its first 8 ticks, falling slowly.

CONFETTI 

A 2 px scrap that flips flat and upright as it falls. Always present.

STAR 

A small plus sign, falling slowly.

DUST 

A puff that slows to a stop and shrinks to a speck (see SIZZLE_DUST).

◆ BannerStyle

enum fx::BannerStyle : uint8_t

Banner colour styles (the game's SIZZLE_STYLES decide which exist).

Enumerator
B_RAINBOW 

The casino rainbow.

B_GOLD 

Gold.

B_RED 

Red.

B_CYAN 

Cyan.

B_WHITE 

White.

Function Documentation

◆ easeCurve()

int fx::easeCurve ( const int16_t *  curve,
int  t,
int  n 
)

Ease through a curve table.

Parameters
curveA 17-point table (EASE_CUBIC ...), or nullptr for linear.
tTime, 0..n.
nDuration.
Returns
0 at t <= 0, 256 at t >= n, the curve in between (interpolated).

◆ ease()

int fx::ease ( Ease  e,
int  t,
int  n 
)
inline

Ease: progress through a curve.

Parameters
eWhich curve.
tTime, 0..n (clamped).
nDuration (frames, for instance).
Returns
0..256 (OUT_BACK and OUT_BOUNCE overshoot 256 on the way).

◆ bounce()

int fx::bounce ( int  t,
int  n 
)
inline

The OUT_BOUNCE curve.

Parameters
tTime, 0..n.
nDuration.
Returns
0..256 (with the bounces).

◆ isin()

int fx::isin ( int  a)

Integer sine.

Parameters
aAngle in 1/256 turns (any value: it wraps).
Returns
-256..256.

◆ icos()

int fx::icos ( int  a)
inline

Integer cosine.

Parameters
aAngle in 1/256 turns.
Returns
-256..256.

◆ rnd()

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.

Returns
32 random bits.

◆ rndRange()

int fx::rndRange ( int  lo,
int  hi 
)

A random number in a range, for presentation.

Parameters
loThe smallest value.
hiOne past the largest value.
Returns
lo .. hi-1 (lo if hi <= lo).

◆ reseed()

void fx::reseed ( )

Restart rnd() from its fixed seed.

◆ shake()

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.

Parameters
framesHow many ticks it lasts.
amplitudeThe 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.

◆ shaking()

bool fx::shaking ( )

Whether a shake is running.

Returns
true until it has counted down.

◆ applyShake()

void fx::applyShake ( int  y0,
int  y1,
int  fill = -1 
)

Shake the finished framebuffer: call after drawing, before the flush.

Parameters
y0,y1The 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.

◆ shakeTick()

void fx::shakeTick ( )

Count the shake down one tick: once per logic tick.

◆ shakeStop()

void fx::shakeStop ( )

Stop the shake at once.

◆ spawn()

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.

Parameters
kIts kind.
x,yWhere it starts, in pixels.
vx16Horizontal speed in 1/16 px per tick (-127..127).
vy16Vertical speed in 1/16 px per tick (-127..127; negative is up).
lifeHow many ticks it lives.
colourIts colour.

◆ burst()

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.

Parameters
kTheir kind.
x,yThe centre.
nHow many.
speed16Top speed in 1/16 px per tick (each gets half to all of it).
colourTheir colour.

◆ fountain()

void fx::fountain ( int  x,
int  y,
uint8_t  n 
)

A fountain of confetti thrown up from a point (a win).

Parameters
x,yWhere it springs from.
nHow many pieces.

◆ particles()

bool fx::particles ( )

Whether any particle is still flying.

Returns
true while one is alive.

◆ particlesAlive()

bool fx::particlesAlive ( )
inline

The same as particles().

Returns
true while a particle is alive.

◆ banner()

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").

Parameters
textThe text (copied; at most SIZZLE_BANNER_CHARS - 1 characters).
sIts style.
cyThe row its centre sits on.
framesHow many ticks it stays up, blinking out at the end (default 70).

One banner at a time: a new one replaces the last.

◆ holdBanner()

void fx::holdBanner ( bool  on)

Keep the banner up (before it blinks out) until let go.

Parameters
ontrue to hold it; false to let it blink out.

◆ bannerActive()

bool fx::bannerActive ( )

Whether a banner is showing.

Returns
true until it has blinked out.

◆ floatText()

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.

Parameters
textThe text (copied; at most SIZZLE_FLOAT_CHARS - 1 characters).
x,yWhere it starts.
colourIts 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.

◆ drawFloats()

void fx::drawFloats ( )

Draw the floating texts: while drawing, on top of the scene.

◆ activeRows()

bool fx::activeRows ( int &  lo,
int &  hi 
)

The band of rows everything transient covers (particles, floats, banner, shake): what a partial redraw must include.

Parameters
loGets the top row.
hiGets the bottom row.
Returns
false if nothing is moving (lo and hi are then meaningless).

◆ clear()

void fx::clear ( )

Remove every particle, float and the banner at once (and stop a shake).

◆ update()

void fx::update ( )

Move everything on by one tick: once per logic tick.

◆ drawParticles()

void fx::drawParticles ( uint8_t  dust = 2)

Draw the particles: while drawing, on top of the scene.

Parameters
dustThe size of a DUST puff in pixels (default 2).

◆ drawBanner()

void fx::drawBanner ( )

Draw the banner, if one is showing: while drawing, last.

Variable Documentation

◆ EASE_CUBIC

const int16_t fx::EASE_CUBIC[17]
extern

The curves' tables (17 points, 0..256), for easeCurve().