C#MonoGame Platformer:平台靠墙移动时结结巴

时间:2018-07-02 15:27:59

标签: c#

因此,在我制作的平台游戏中,每当玩家靠墙移动时,所有或某些其他平台都将非常快速地来回移动。

平台移动代码(它是侧滑车,因此平台(而不是播放器)左右移动):

    public void MovePlatformsIfPossible(GameTime gameTime, Player player)
    {
        bool ResetAllPlatforms = false;
        bool IntersectedAtLeastOnce = false;
        Vector2 FinalMove = Vector2.Zero;

        foreach (Platform plat in Platforms)
        {
            plat.OldPosition = plat.Position;
        }

        foreach (Platform plat in Platforms)
        {
            plat.Position += Movement * (float)gameTime.ElapsedGameTime.TotalMilliseconds / 17;

            plat.UpdateRectangles();

            Vector2 smallerMove = Movement;

            while (plat.Rect.Intersects(player.Rect))
            {
                IntersectedAtLeastOnce = true;

                if (smallerMove.X > -1 && smallerMove.X < 1)
                {
                    ResetAllPlatforms = true;
                    ResetEveryPlatform();
                    break;
                }
                plat.Position = plat.OldPosition;
                smallerMove = SubtractATenthOfMovement(smallerMove);
                plat.Position += smallerMove;
                plat.UpdateRectangles();
                FinalMove = smallerMove;
            }

            if (ResetAllPlatforms)
                break;
        }
   } 

我尝试添加许多不同的东西以使其正常工作,但这只是所有可行的东西的结合。

感谢您的帮助。

0 个答案:

没有答案