Listing 3: Function RenderSprites


/* RenderSprites - Draw all sprites into the master
   bitmap.  This routine does no on-screen drawing */
void RenderSprites(HWND hwnd)
{
int maxx,maxy,x,y,baseInc;
BYTE *base,*s;
struct SPRITE *sprite;

    maxx=info->bmiHeader.biWidth;
    maxy=-info->bmiHeader.biHeight;
    GdiFlush();
    sprite=firstSprite;
    while(sprite!=NULL) {
        if( (sprite->xLoc>0) && 
            (sprite->yLoc>0) && 
            ((sprite->xLoc+sprite->w)<maxx) && 
            ((sprite->yLoc+sprite->h)<maxy) ) {
            
            s=sprite->base;
            base=bitmap+(sprite->yLoc*maxx)+sprite->xLoc;
            baseInc=maxx-sprite->w;
            x=0;
            y=sprite->h;
            while(y) {
                if(*s!=*sprite->base)
                    *base=*s;
                base++;
                s++;
                x++;
/* Is it time to wrap to the next line? */
                if(x==sprite->w) {
                    base+=baseInc;
                    x=0;
                    y--;
                    }
                }
            }
        sprite=sprite->next;
        }
    GdiFlush();
}
/* End of File */