【问题标题】:Trouble with Collision in Java (with Rectangles)Java 中的冲突问题(使用矩形)
【发布时间】: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


【解决方案1】:

我找到了问题。

矩形的定位有一个简单的错误,我在 if 语句中有一个变量错误。不过还在学习! =D

【讨论】:

    猜你喜欢
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-29
    • 1970-01-01
    • 2017-11-22
    相关资源
    最近更新 更多