나는 내 맵과 충돌 작업을 수행하지만 내 플레이어가 충돌 할 때 나는 플레이어의 움직임을 멈추고 나는 걷지 않는다. 한 방향에 대한 플레이어를 막을 방법을 모르는충돌 작업은 있지만 콜 싱온 방향을 어떻게 알 수 있는지 모른다.
플레이어와지도 아래의 내 코드 충돌 이동하지 않습니다 플레이어에 대한 코드가 GAME1 클래스에
public bool IsCollisionTile(Rectangle player)
{
foreach(Rectangle rect in this._collisionObject)
{
if (rect.Intersects(player))
{
return true;
}
}
return false;
}
그
if (mapLoader.IsCollisionTile(player.getDestinationRect()))
{
player.setCantWalk(true);
}
그 Player.cs
private bool _cantWalk;
public void Update()
{
this._destinationRectangle.X = (int)_position.X;
this._destinationRectangle.Y = (int)_position.Y;
this._destinationRectangle.Width = _texture.Width;
this._destinationRectangle.Height = _texture.Height;
if(Keyboard.GetState().IsKeyDown(Keys.Up))
{
if (_cantWalk == false)
{
_position.Y--;
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.Down))
{
if (_cantWalk == false)
{
_position.Y++;
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.Right))
{
if (_cantWalk == false)
{
_position.X++;
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.Left))
{
if (_cantWalk == false)
{
_position.X--;
}
}
}
public void setCantWalk(bool walk)
{
_cantWalk = walk;
}
이 간단한 방법 나에게
플레이어를 X 축에서 이동 한 다음 충돌 검사를 수행 한 다음 Y 축을 검사하고 다시 확인하고 시도하는 중 하나를 되돌릴 수 있습니다 s) 검사가 ... 이상하게 보이지는 않지만 옵션입니다 –
안녕하세요.하지만 초보자이고 어떻게 해야할지 모르겠습니다. –