As part of the Gameduino Kickstarter campaign, four rewards were “I’ll hack up your game idea.” Watterott Electronic took one of the rewards, and simply asked for a Gameduino version of their logo, animated.
Here is the sketch for download, and here is the finished animation loop running on the Gameduino.
The background layer is a simple black-to-gray color ramp, using the same program (bgstripes.fs) as the Background color register demo.
There’s a little more code in the loop to make the ramp fade in and out.
It seemed a nice idea to make the Watterott spark animate. Starting with a static version of the spark, five different versions with the points moved slightly:
painting each 25x12 character version on sucessive frames - and adding a 1 pixel random scroll - gives a constantly jittery spark:
GD.wr16(SCROLL_X, random(-1, 2));
GD.wr16(SCROLL_Y, random(-1, 2));
prog_uchar *src = logobg_pic + (12 * 25 * jitter);
for (byte y = 0; y < 12; y++) {
GD.copy(atxy(24, 12 + y), src, 25);
src += 25;
}
The logo itself is a sprite layer, sourced from this image:
and encoded as 16-color sprites. Each animation frame is 16x48 pixels, so revealing the logo from left-to-right is done by drawing animation frame 0, then frame 1 is drawn 16 pixels to the right, etc.
Taking a single 16x16 version of the spark:
and running a simple system of 200 particles completes the effect. Each particle is ‘born’ at the same X-coordinate as the logo reveal, falls across the screen with a random velocity, and ‘dies’ when it passes the bottom of the screen. The sprite drawing is double-buffered using the SPR_PAGE register so there is no tearing.
Keeping track of the spark position and velocity:
#define NSPR 200
struct spr {
int x, y;
signed char vx, vy;
} sprites[NSPR];
static void born(byte i)
{
sprites[i].x = focusx + qrand(4);
sprites[i].y = focusy -16 + qrand(5);
sprites[i].vx = -8 + qrand(4);
sprites[i].vy = -qrand(4) - 1;
}
static void kill(byte i)
{
sprites[i].y = 309;
sprites[i].vx = 0;
sprites[i].vy = 0;
}
And the main loop to move and draw the sparks:
struct spr *ps;
for (i = 0, ps = &sprites[i]; i < NSPR; i++, ps++) {
draw_spark(ps->x, ps->y, 0, (i & 7));
ps->x += ps->vx;
ps->y += ps->vy;
ps->vy++;
if ((ps->x < 0) || (ps->x > 400) || (ps->y > 310)) {
if (sparking)
born(i);
else
kill(i);
}
}
Last modified $Date: 2011-09-17 19:07:44 -0700 (Sat, 17 Sep 2011) $