我正在尝试在一个Character类中编写一个函数,这样当它与一个Wall对象(它的平台游戏)的顶部碰撞时,它会返回true. 到目前为止,我在Character课堂上有这个:
private boolean isTouchingTopOfWall() {
for (Wall wall: game.getPanel().getWalls())
if (getBounds().intersects(wall.getBounds()))
return true;
return false;
}
Character和Wall类中有两个函数,如下所示:
public Rectangle getBounds() {
return new Rectangle(x, y, game.getBlockSize(), game.getBlockSize());
}
除了当Character对象与对象的侧面碰撞时,它还可以完美地工作,当我想要它时Wall它也会返回true,以便它只true在从顶部碰撞时返回。我怎样才能做到这一点?
谢谢。