Some times ago I found an interesting bomberman clone written in C with some cool graphics effects in it.

Trying to understand how it achieved those effects, I put up togheter the minimum code required to reproduce them, but still have trouble understanding some very obscure (to me) pieces...

Especially this routine:

- {l Code}: {l Select All Code}
`void Rotator(void)`

{

u32 ix, iy;

u16 px, py, px2, py2, incx, incy;

u32 nMultiplier;

u8 *pScr, *pPic;

SDL_LockSurface(screen);

// Multiplicateur (Zoom).

#if RZ_TYPE == 0

nMultiplier = 0x08000 + ((0x0060 + pCos[(gRoto.nAngle + 192) & 0xFF]/2) << 9);

#else

nMultiplier = 0x08000 + ((0x0060 + pCos[gRoto.nZoom]/2) << 9);

#endif

// Val sin et cos (Roto).

incx = (pCos[gRoto.nAngle] * nMultiplier) >> 16;

incy = (pSin[gRoto.nAngle] * nMultiplier) >> 16;

// Point de départ.

// x' = x cos f - y sin f

// y' = y cos f + x sin f

px = (128 << 8) - ((ROTO_CTR_X * incx) - (ROTO_CTR_Y * incy));

py = (128 << 8) - ((ROTO_CTR_Y * incx) + (ROTO_CTR_X * incy));

// Loop.

pScr = (u8*)screen->pixels;

pPic = (u8*)pRotoPic->pixels;

pPic += (gRoto.nScroll & 63) << 8; // Scroll.

s32 nPitchDiff = screen->pitch - SCREEN_WIDTH;

for (iy = 0; iy < SCREEN_HEIGHT; iy++)

{

px2 = px;

py2 = py;

for (ix = 0; ix < SCREEN_WIDTH; ix++)

{

*pScr++ = *(pPic + ((py2 >> 8) << 8) + (px2 >> 8));

px2 += incx;

py2 += incy;

}

pScr += nPitchDiff;

//incx++; // Déformation.

px -= incy;

py += incx;

}

#if RZ_TYPE == 0

gRoto.nAngle += 1;

#else

// Déplacement des rotations, zooms, scrolls...

gRoto.nAngCnt--;

gRoto.nAngCnt &= 63;

if (gRoto.nAngCnt == 0)

{

gRoto.nAngVar = (gRoto.nAngVar + 1) & 3;

gRoto.nAngCnt = (rand() & 63) | 16;

}

if (gRoto.nAngVar == 1) gRoto.nAngle++;

else if (gRoto.nAngVar == 3) gRoto.nAngle--;

else gRoto.nScroll++;

gRoto.nZoomCnt--;

gRoto.nZoomCnt &= 63;

if (gRoto.nZoomCnt == 0)

{

gRoto.nZoomVar = (gRoto.nZoomVar + 1) & 1;

gRoto.nZoomCnt = (rand() & 63) | 32;

}

if (gRoto.nZoomVar == 0) gRoto.nZoom++;

#endif

SDL_UnlockSurface(screen);

}

I can't understand some numbers come from, like in

ornMultiplier = 0x08000 + ((0x0060 + pCos[(gRoto.nAngle + 192) & 0xFF]/2) << 9);

, are them some kind of mathematical constants?px = (128 << 8) - ((ROTO_CTR_X * incx) - (ROTO_CTR_Y * incy));

I've tracked down the author website (in french) and found a simplistic explanations about some of the operations, but I can't completly understand them all.

Does anyone have some tips about this code?

I attached the full example to this post.