내 게임의 충돌에 문제가 있습니다. 게임은 "타일 기반"입니다. 문제는 플레이어가 그 안에 들어가는 것을 막는 타일을 배치 할 때 타일에 인접한 무한한 수직 및 수평 장벽을 생성합니다. 그것은이 작업을 수행하는 이유 나도 몰라충돌이 작동하지 않습니다.
double d = delta;
Point oldVerticalPoint = new Point(point.getX(), point.getY());
if (Keyboard.isKeyDown(Keyboard.KEY_UP))
point.setY((float) (point.getY() - (speed * d)));
if (Keyboard.isKeyDown(Keyboard.KEY_DOWN))
point.setY((float) (point.getY() + (speed * d)));
for (int x = 1; x <= game.map.width; x++) {
for (int y = 1; y <= game.map.height; y++) {
Block block = game.map.getBlock(x, y);
if (block instanceof BlockWall) {
BlockWall b = (BlockWall) block;
Point blockPoint = Block.getStandardBlockCoords(x, y);
Point playerPoint = game.thePlayer.point;
if (playerPoint.getY() > blockPoint.getY() && playerPoint.getY() < <blockPoint.getY() + Block.LENGTH)
game.thePlayer.point = oldVerticalPoint;
}
}
}
Point oldHorizontalPoint = new Point(point.getX(), point.getY());;
if (Keyboard.isKeyDown(Keyboard.KEY_LEFT))
point.setX((float) (point.getX() - (speed * d)));
if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
point.setX((float) (point.getX() + (speed * d)));
for (int x = 1; x <= game.map.width; x++) {
for (int y = 1; y <= game.map.height; y++) {
Block block = game.map.getBlock(x, y);
if (block instanceof BlockWall) {
BlockWall b = (BlockWall) block;
Point blockPoint = Block.getStandardBlockCoords(x, y);
Point playerPoint = game.thePlayer.point;
if (playerPoint.getX() > blockPoint.getX() && playerPoint.getX() < blockPoint.getX() + Block.LENGTH)
game.thePlayer.point = oldHorizontalPoint;
}
}
}
:
여기 내 코드입니다. 한 가지 분명한 것은 두 가지 충돌 감지가있는 이유입니다. 플레이어가 벽에 수평으로 이동하고 간단한 타일과 같은 무언가에 수직으로 움직이는 경우 플레이어는 완전히 움직이지 않을 것입니다. 또한 getStandardBlockCoords는 블록 X 및 Y가 경우 때문에, 예를 들어 사용되는 X = 1 및Y = 2 블록이 두 번째 열의 첫 번째 행을 의미.되고 이 메서드는 이것을 단순히 픽셀 좌표로 변환합니다.
저는 LWJGL과 Slick2D를 사용하고 있습니다. 도움?