0

在 BrickBreaker 游戏中,我有以下代码来检查球与杆的碰撞:

if(ball.x + ball.getWidth() > bar.x && ball.x < bar.x + (bar.getWidth()/5)) {
        ...
    }

    else if(ball.x + ball.getWidth() > bar.x + (bar.getWidth()/5) && ball.x < bar.x + (2*bar.getWidth()/5)) {
        ...
    }

    else if(ball.x + ball.getWidth() > bar.x + (2*bar.getWidth()/5) && ball.x < bar.x + (3*bar.getWidth()/5)) {
        ...
    }

    else if(ball.x + ball.getWidth() > bar.x + (3*bar.getWidth()/5) && ball.x < bar.x + (4*bar.getWidth()/5)) {
        ...
    }

    else if(ball.x + ball.getWidth() > bar.x + (4*bar.getWidth()/5) && ball.x < bar.x + bar.getWidth()) {
        ...
    }

但如果球没有击中横杆,它会说,发生了碰撞。我的碰撞检查出了什么问题?

4

1 回答 1

0

我的碰撞检查出了什么问题?

奇怪的数学。检查此圆矩形碰撞检测(交叉点)

于 2012-08-05T14:18:02.187 回答