Hey All im looking for someone to look over my collision detection function its not complicated or anything and it normally works well but right now I am having some issues with it.
Here is the collision detection function:
int CollDet(PlayerShip sprite1, EnemyShip sprite2)
{
RECT rect1;
rect1.left = sprite1.x + 1;
rect1.top = sprite1.y + 1;
rect1.right = sprite1.x + sprite1.width-1;
rect1.bottom = sprite1.y + sprite1.height-1;
RECT rect2;
rect2.left = sprite2.x + 1;
rect2.top = sprite2.y + 1;
rect2.right = sprite2.x + sprite2.width-1;
rect2.bottom = sprite2.y + sprite2.height-1;
RECT dest;
return IntersectRect(&dest,&rect1,&rect2);
}
Here is how I check for collision:
for(int count = 0; count < NUMFIRE; count++)
{
if(CollDet(PlayerGun[count],EnemyPawn[0]))
{
EnemyPawn[0].isAlive = false;
}
if(CollDet(PlayerGun[count],EnemyPawn[1]))
{
EnemyPawn[1].isAlive = false;
}
if(CollDet(PlayerGun[count],EnemyPawn[2]))
{
EnemyPawn[2].isAlive = false;
}
}
Here is the for statement that draws the enemy sprites on the screen as you can see it has an if statement that checks if they still should be drawn:
for (int count = 0; count < EnemyPawnCount; count++)
{
if(!EnemyPawn[count].isAlive == false)
{
position3.x = (float)EnemyPawn[count].x;
position3.y = (float)EnemyPawn[count].y;
sprite_handler->Draw(
enemy_pawn,
NULL,
NULL,
&position3,
D3DCOLOR_XRGB(255,255,255));
}
}
So im sure its a basic problem but I dont see it so I need some fresh eyes.Thanks for having a look.