编辑:这里是完整的代码:https ://dl.dropboxusercontent.com/u/65678182/assignment1.rar非常感谢任何可能的帮助!
我正在尝试制作突围游戏的副本,但在检查两个对象(球和桨)是否相交时遇到问题。
我现在有这种碰撞检测方法:
public static void handleCollisions()
{
System.out.println(ball.getBounds()); // just to check that they
System.out.println(paddle.getBounds()); //are there and moving correct
if (ball.getBounds().intersects(paddle.getBounds()))
{
System.out.println("collision");
}
}
我很确定 getBounds 可以正常工作,因为我从 println 获得了这些输出: java.awt.Rectangle[x=393,y=788,width=14,height=14] java.awt.Rectangle[x= 350,y=350,宽度=100,高度=10]
getBounds code:
public static Rectangle getBounds()
{
return new Rectangle(x, y, radius*2, radius*2);
}
我可以看到它们在重叠的一点上移动,但该方法从未检测到它。
我对此很陌生,所以希望它只是某个地方的一些愚蠢的错误,感谢您的帮助。如有必要,我可以发布更多代码,但不希望。