所以我正在使用 C# 在 XNA 中创建一个游戏,并且我在随机位置创建了墙壁,我试图阻止它们穿过它们/当它们击中它们时被传送到屏幕上的点。(注意,左右现在有效,只是顶部和底部)
if (collision(wallRect[k], wallColours, pacmanRect, pacmanColor, 0))
//Collision works, not an issue here
{
if (pacmanRect.Bottom > wallRect[k].Top && pacmanRect.Top < wallRect[k].Bottom)
{
if (pacmanRect.Right >= wallRect[k].Left
&& pacmanRect.Right < wallRect[k].Right)
{
pacmanPos.X = wallRect[k].X - frameSize.X;
//frameSize is the size of the pacman sprite
}
else if (pacmanRect.Left <= wallRect[k].Right
&& pacmanRect.Left > wallRect[k].Left)
{
pacmanPos.X = wallRect[k].X + frameSize.X / 8;
}
}
else if (pacmanRect.Right > wallRect[k].Left && pacmanRect.Left < wallRect[k].Right)
{
if (pacmanRect.Bottom >= wallRect[k].Top)
{
pacmanPos.Y = wallRect[k].Y - frameSize.Y / 8;
}
else if (pacmanRect.Top <= wallRect[k].Bottom)
{
pacmanPos.Y = wallRect[k].Y + frameSize.Y / 8;
}
}
playSound(collisionSoundInstance);
}
这是游戏循环中 pacmanPos 更新的最后一点。那么我将如何使墙壁成为真正的墙壁,而您不能穿过它们呢?