【发布时间】:2016-05-21 06:33:21
【问题描述】:
我在 Java 中遇到矩形之间的冲突问题。
我对编程很陌生,这是我的第一个“严肃”项目(它是对 pong lol 的再创作),但无论如何,这是我目前的方法:
public static void Collision(){
if(ballArea().intersects(Background.gameTop())){
isGoingUp = false;
System.out.println("hit");
} else if(ballArea().intersects(Background.gameBottom())){
isGoingUp = true;
System.out.println("hit");
} else if(ballArea().intersects(Background.gameRight())){
isGoingRight = false;
System.out.println("hit");
} else if(ballArea().intersects(Background.gameLeft())){
isGoingUp = true;
System.out.println("hit");
}
}
public static Rectangle ballArea(){
return new Rectangle(ballXPos, ballYPos, ballXSize, ballYSize);
}
到目前为止,我在屏幕的两侧都有矩形,但我无法让碰撞起作用。谢谢您的帮助。 :)
//编辑,如果你需要更多,我可以发布更多
【问题讨论】:
-
Pong 没什么好笑的!
-
当然。我只是觉得我把 Pong 称为我的第一个“严肃”项目是很愚蠢的。
标签: java collision-detection collision rectangles