안녕하세요. C#/XNA에 약간의 게임을 만들고 있는데 충돌로 인해이 문제가 있습니다.C# Rectangle 충돌 감지가 작동하지 않습니다.
내 코드에서 내가하는 일은 정상적인 플레이어 이동을 만드는 것입니다. 예를 들어 위로 키를 누른 경우 플레이어 CanGoTop == true를 확인하는 것뿐입니다. bollean이 false 인 경우
if (keyState.IsKeyDown(Keys.Up) && CanGoTop == true)
{
bla bla bla
}
나는 왼쪽이 작업을 수행, 오른쪽, 위, 아래, 그리고 플레이어는 속도, x와 .Y을 설정 movemnt의 그 4 문에서도 후 다른 사람의 한 Statment이 있습니다 (이동하지 않습니다 0으로)
이제 Player 클래스 내에서 메서드를 만들었습니다. 그냥보고있는 것만으로도 여기에 무슨 일이 일어나는지 설명해야한다고 생각하지 않습니다.
public void RectangleInteraction(Rectangle anotherRectangle)
{
if (playerRectangle.Bottom <= anotherRectangle.Top &&
playerRectangle.Top >= (anotherRectangle.Top - playerRectangle.Height) &&
playerRectangle.Left <= anotherRectangle.Right &&
playerRectangle.Right >= anotherRectangle.Left)
{
CanGoBot = false;
}
else CanGoBot = true;
if (playerRectangle.Top >= anotherRectangle.Bottom &&
playerRectangle.Bottom <= (anotherRectangle.Bottom + playerRectangle.Height) &&
playerRectangle.Left <= anotherRectangle.Right &&
playerRectangle.Right >= anotherRectangle.Left)
{
CanGoTop = false;
}
else CanGoTop = true;
if (playerRectangle.Top <= anotherRectangle.Bottom &&
playerRectangle.Bottom >= anotherRectangle.Top &&
playerRectangle.Right <= anotherRectangle.Left &&
playerRectangle.Left >= (anotherRectangle.Left - playerRectangle.Width))
{
CanGoRight = false;
}
else CanGoRight = true;
if (playerRectangle.Top <= anotherRectangle.Bottom &&
playerRectangle.Bottom >= anotherRectangle.Top &&
playerRectangle.Left >= anotherRectangle.Right &&
playerRectangle.Right <= (anotherRectangle.Right + playerRectangle.Width))
{
CanGoLeft = false;
}
else CanGoLeft = true;
}
내 Game1.cs Update() 메소드에서 플레이어 insta를 사용합니다. nce는 그 방법을 호출하고, 지금은 저를 괴롭히는 것입니다. CanGoLeft에서는 작동하지만 다른 3 개의 bool에서는 작동하지 않습니다.
나는 왜 여기에 내 InGameMsgs가있는 4 스크린 샷이 있는지 알려주지 않습니다. 내 코드로 메시지를 확인하면 CollisionLogic이 좋다고 알려주지 만 다른 것은 잘못되었습니다. 그럼 왜 CanGoLeft 만 작동합니까? :/
귀하의 시간과 도움에 감사드립니다.