I've only just started out in SDL , and have run into a problem. The collision detection code below works perfectly when it's in the main function. however , I didn't like having the code repeated for each collsion check , and so copied it into a function.
Here something goes wrong.
Have spent the last few days swearing at the complier , but have not managed to figure it out. Basically , rather then destroying the object which the bullet hits ( in this case house bricks' , as it's a space invaiders clone ) , the bullet will destroy every object in it's Y axis path ( alothough the bullet is still removed from the game when it hits the first brick , every other single object in it;s path also dies )
Here is the code :
if (imageoverlap(fire.x,fire.y,120+(12*xx),165+(12*(yy-1)),bullet->w,brick->w,bullet->h,brick->h))
{
fire.active=0;
house2[xx] =0;
}
int imageoverlap(int ob1x,int ob1y,int ob2x,int ob2y,int ob1w,int ob2w,int ob1h,int ob2h)
{
if ((ob1x >ob2x) && (ob1x < ob2x + ob2w))
{
if ((ob1y > ob2y)&& ((ob1y < ob2y) + ob2h))
{
return 1;
}
}
if ((ob1x+ob1w >ob2x) && (ob1x+ob1w < ob2x + ob2w))
{
if ((ob1y > ob2y)&& ((ob1y < ob2y) + ob2h))
{
return 1;
}
}
return 0;
}
Many thanks for any help

