我一直在尝试用 C 编写一些碰撞检测代码,下面是我目前拥有的函数,它每帧调用一次,但是由于某种原因,当 2 个精灵重叠时,碰撞不起作用
short int Collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
{
int left1, left2;
int right1, right2;
int top1, top2;
int bottom1, bottom2;
left1 = x1;
left2 = x2;
right1 = x1 + w1;
right2 = x2 + w2;
top1 = y1;
top2 = y2;
bottom1 = y1 + h1;
bottom2 = y2 + h2;
if ((bottom1 < top2)||(top1 > bottom2)||(right1 < left2)||(left1 > right2))
{
return(1);
}
else
{
return(0);
}
};
if (Collision ==1)
{
//code for collision here
}
任何指向正确方向的指针将不胜感激