如图一个经典的乒乓球小游戏,我使用最常用的检测球与球拍碰撞的公式发现当球速很快的时候,乒乓球有可能会miss掉球拍,从而造成一方扣分,为了不miss掉球拍,我试过使用intersect,就是给球和球拍加一个边缘盒子,如果盒子交错了,就表示碰撞了,但是代码实测后发现还是会存在球miss球拍的情况,有没有大神能给点思路,下面是那个常用的碰撞检测的代码,我现在的想法是能不能吧长方形的球拍变成长方体,但是不知道怎么实现
、、、
private bool CollisionOccurred()
{
// assume no collision
bool retval = false;
// heading towards player one
if (m_ball.DX < 0)
{
Rectangle b = m_ball.Rect;
Rectangle p = m_paddle1.Rect;
retval =
b.Left < p.Right &&
b.Right > p.Left &&
b.Top < p.Bottom &&
b.Bottom > p.Top;
}
// heading towards player two
else // m_ball.DX > 0
{
Rectangle b = m_ball.Rect;
Rectangle p = m_paddle2.Rect;
retval =
b.Left < p.Right &&
b.Right > p.Left &&
b.Top < p.Bottom &&
b.Bottom > p.Top;
}
return retval;
、、、