간단한 2D 게임 인 Arkanoid 게임에서 프로젝트를 진행하고 있습니다.충돌 감지 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.
가 물어보세요. 사전에 내 영어 :(
감사에 대한
죄송합니다