It's really simple, probably ineffective, untested, won't work with scaled, rotated, or stretched sprites, and requires you use a colorkey or something.
I hope it's not illegal to name it with the db prefix. I did that for simplicity.
int getPixelColor(int x, int y)
{
// credit to Willie Mundermuffin
//**NOTE**: Pixels per row = dbGetPixelsPitch() / 4.
//**NOTE**: Pixel number = ((y - 1) * (dbGetPixelsPitch() / 4)) + x.
int color = 0;
dbLockPixels();
int* pixel = (int*)dbGetPixelsPointer();
color = *(pixel + x + ((y - 1) * (dbGetPixelsPitch() / 4)));
dbUnlockPixels();
return color;
}
int dbPerPixelCollision(int iSpriteA, int iSpriteB, DWORD TransparentColor)
{
dbCreateBitmap(1, dbSpriteWidth(iSpriteA), dbSpriteHeight(iSpriteA));
dbSetCurrentBitmap(1);
dbPasteImage(dbSpriteImage(iSpriteA), 0, 0);
dbCreateBitmap(2, dbSpriteWidth(iSpriteB), dbSpriteHeight(iSpriteB));
dbSetCurrentBitmap(2);
dbPasteImage(dbSpriteImage(iSpriteB), 0, 0);
dbSetCurrentBitmap(1);
for (int a = 0; a < dbSpriteWidth(iSpriteA); a++)
{
for (int a1 = 0; a < dbSpriteHeight(iSpriteA); a1++)
{
dbSetCurrentBitmap(1);
DWORD cur_pixel_color = getPixelColor(a, a1);
if (cur_pixel_color != TransparentColor)
{
for (int b = 0; b < dbSpriteWidth(iSpriteB); b++)
{
for (int b1 = 0; b < dbSpriteHeight(iSpriteB); b1++)
{
dbSetCurrentBitmap(2);
DWORD this_pix_color = getPixelColor(b, b1);
if (this_pix_color != TransparentColor)
{
if ((dbSpriteX(iSpriteA) - dbSpriteOffsetX(iSpriteA) + a) == (dbSpriteX(iSpriteB) - dbSpriteOffsetX(iSpriteB) + b))
{
if ((dbSpriteY(iSpriteA) - dbSpriteOffsetY(iSpriteA) + a1) == (dbSpriteY(iSpriteB) - dbSpriteOffsetY(iSpriteB) + b1))
{
dbDeleteBitmap(1);
dbDeleteBitmap(2);
return 1;
}
}
}
}
}
}
}
}
dbDeleteBitmap(1);
dbDeleteBitmap(2);
return 0;
}
Fixed a couple syntax errors. I'm bad at that.