我做一个简单的2D游戏,的打砖块游戏项目。冲突检测2D
我正常工作,几乎所有的东西,但我被困在球与砖,即碰撞,在碰撞的时候,应该像一堵墙,扭转了球的方向。
,就会出现问题,以查看是否是否用砖块的碰撞是在侧碰撞水平或垂直时,例如,应在不改变Y轴只投资在X轴方向,反之亦然。
我没有得到发现,检查我的代码。
public void detectCollisionWithBricks() {
for (int i = 0; i < brickGroup.length; i++) {
for (int j = 0; j < brickGroup[i].length; j++) {
if (brickExists[i][j]) {
if (getEllipse().intersects(
brickGroup.brick[i][j]
.getRectangle())) {
incY*=-1;
incX*=-1;
brickExists[i][j] = false;
}
}
}
}
}
代码:
-brickGroup: bidimensional array of bricks
-brick: class painting a brick in the panel
-brickExist: bidimensional array whit se same size as brickGroup, if false, doesn't paint the brick.
-getEllipse(): returns an Ellipse2D.Double, with the coordinates of the ball.
-getRectangle(): returns an Rectangle2D.Double, with the coordinates of the brick.
-incX: increases the X position of the ball.
-incY: increases the Y position of the ball.
问,如果你不明白一些代码。
对不起,我的英语:(
在此先感谢