void AnimUpdateTile(AnimTile *a, int *t, int *f, graphic_t *gptr, u8 *tmem) { (*t)++; if( (*t) > a->freq[(*f)]) { (*t) = 0; if( (*f) < a->len - 1) { (*f)++; } else { (*f) = 0; } swiCopy(gptr->tileEntries+(a->ID[(*f)]*4)*64, tmem + a->ID[0]*4*64, 32); swiCopy(gptr->tileEntries+(a->ID[(*f)]*4+1)*64, tmem + (a->ID[0]*4+1)*64, 32); swiCopy(gptr->tileEntries+(a->ID[(*f)]*4+2)*64, tmem + (a->ID[0]*4+2)*64, 32); swiCopy(gptr->tileEntries+(a->ID[(*f)]*4+3)*64, tmem + (a->ID[0]*4+3)*64, 32); } }
//create a sprite with a random position, speed, and size void randomSprite(mySprite* s) { //pick a random color index u8 c = rand() % 256; //two pixels at a time u16 color = c | (c << 8); //create a randomly oriented sprite going off in a random direction createSprite(s, rand() % 256, rand() % 192, 0, sizes[(rand() % 12)], SpriteColorFormat_256Color, rand() % 4 - 2, rand() % 4 - 2); //dont let sprites get stuck with 0 velocity if(s->dx == 0 && s->dy == 0) { s->dx = rand() % 3 + 1; s->dy = rand() % 3 + 1; } //the size (in pixels) is encoded in the low 12 bits of the Size attribute (shifted left by 5) //we load new graphics each time as this is as much a test of my allocator as an example of api usage if(s->gfx) { swiCopy(&color, s->gfx, ((s->size & 0xFFF) << 4) | COPY_MODE_FILL); } else { s->alive = false; } }