After a break, I started working on this again and all it seems to be doing is checking for a rectangle collision. The per pixel part seems to be always returning false, and I can't figure out why. Here's the updated code...
Code:
bool CollideYou(int index)
{
int left1, left2;
int right1, right2;
int top1, top2;
int bottom1, bottom2;
left1 = BulletsE[index].x;
left2 = You.x;
right1 = BulletsE[index].x + 5;
right2 = You.x + 99;
top1 = BulletsE[index].y;
top2 = You.y;
bottom1 = BulletsE[index].y + 20;
bottom2 = You.y + 75;
//The basic rectangle collision, seems to be working fine
if (bottom1 < top2) return false;
if (top1 > bottom2) return false;
if (right1 < left2) return false;
if (left1 > right2) return false;
int over_bottom, over_top, over_right, over_left;
if (bottom1 > bottom2) over_bottom = bottom2;
else over_bottom = bottom1;
if (top1 < top2) over_top = top2;
else over_top = top1;
if (right1 > right2) over_right = right2;
else over_right = right1;
if (left1 < left2) over_left = left2;
else over_left = left1;
//This should be giving me pixel perfect 2D collision detection, but
//it's not
int offset1, offset2;
offset1 = ((over_top - You.y) * 99) + over_left;
offset2 = ((over_top - MasterList[index].y) * 5) + over_left;
for (int y = 0; y <= over_bottom-over_top; y++)
{
for (int x = 0; x <= over_right-over_left; x++)
{
if ((!IsPink(ship, x+offset1, y)) && (!IsPink(bulletE, x+offset2, y)))
return true;
}
}
return false;
}
And just incase this has an error
Code:
bool IsPink(SDL_Surface *surface, int x, int y)
{
Uint32 color = SDL_MapRGB(screen->format, 255, 0, 255);
switch (screen->format->BytesPerPixel)
{
case 1:
Uint8 *bufp;
bufp = (Uint8 *)surface->pixels + y*surface->pitch + x;
if (*bufp == color)
return true;
break;
case 2:
Uint16 *bufp1;
bufp1 = (Uint16 *)surface->pixels + y*surface->pitch/2 + x;
if (*bufp1 == color)
return true;
break;
case 4:
Uint32 *bufp2;
bufp2 = (Uint32 *)surface->pixels + y*surface->pitch/4 + x;
if (*bufp2 == color)
return true;
break;
}
return false;
}
Thanks a bunch