public void ElevatorCollision(FPGameProtocol game, float diffX, float diffY)
        {
            FPPlayer player = (FPPlayer)game.Player;
            RectangleF playerRect = player.Rect;
            RectangleF moveRect = this.Rect.WithMove(diffX, diffY);

            if (diffY > 0.0f)
            {
                if (playerRect.IntersectsWithTolerance(moveRect))
                    diffY = 0.0f;
                else
                {
                    foreach (var gameObject in game.GameObjects)
                    {
                        if (gameObject.IsMovable)
                        {
                            if (gameObject.Rect.IntersectsWithTolerance(moveRect))
                            {
                                diffY = 0.0f;
                                break;
                            }
                        }
                    }
                }
            }

            if (Math.Abs(diffX) > 0.0f)
            {
                if (playerRect.IntersectsWithTolerance(moveRect))
                    diffX = 0.0f;
                else
                {
                    foreach (var gameObject in game.GameObjects)
                    {
                        if (gameObject.IsMovable)
                        {
                            if (gameObject.Rect.IntersectsWithTolerance(moveRect))
                            {
                                diffX = 0.0f;
                                break;
                            }
                        }
                    }
                }
            }

            playerRect.Height += FPPlayer.tolerance;

            if (playerRect.IntersectsWithTolerance(moveRect))
            {
                game.MoveWorld(-diffX, 0.0f);
                player.CollisionLeftRight(game);
                game.MoveWorld(0.0f, -diffY);
            }
            else
            {
                foreach (var gameObject in affectedObjects)
                {
                    moveRect = gameObject.Rect.WithMove(diffX, diffY);
                    if (playerRect.IntersectsWithTolerance(moveRect))
                    {
                        game.MoveWorld(-diffX, 0.0f);
                        player.CollisionLeftRight(game);
                        game.MoveWorld(0.0f, -diffY);
                        break;
                    }
                }
            }

            FPGameObject movableOnElevator = null;
            RectangleF movableRect;

            foreach (var movable in game.GameObjects)
            {
                if (movable.IsMovable)
                {
                    moveRect = this.Rect.WithMove(diffX, diffY);
                    movableRect = movable.Rect;
                    movableRect.Height += FPPlayer.tolerance;
                    if (movableRect.Bottom < moveRect.Bottom && movableRect.IntersectsWithTolerance(moveRect))
                    {
                        movableOnElevator = movable;
                        break;
                    }
                    else
                    {
                        foreach (var gameObject in affectedObjects)
                        {
                            moveRect = gameObject.Rect.WithMove(diffX, diffY);
                            if (movableRect.Bottom < moveRect.Bottom && movableRect.IntersectsWithTolerance(moveRect))
                            {
                                movableOnElevator = movable;
                                break;
                            }
                        }
                    }
                }
            }

            if (movableOnElevator != null)
            {
                movableRect = movableOnElevator.Rect.WithMove(diffX, diffY);
                movableOnElevator.Move(diffX, 0.0f);
                if (playerRect.IntersectsWithTolerance(movableRect))
                {
                    game.MoveWorld(-diffX, 0.0f);
                    player.CollisionLeftRight(game);
                }
                movableOnElevator.Move(0.0f, diffY);
                if (playerRect.IntersectsWithTolerance(movableRect))
                {
                    game.MoveWorld(0.0f, -diffY);
                }
            }

            X += diffX;
            Y += diffY;
            foreach (var gameObject in affectedObjects)
                gameObject.Move(diffX, diffY);
        }
        public bool CollisionUpDown(FPGameProtocol game)
        {
            bool isColliding = false;

            foreach (var platform in game.GameObjects)
            {
                if (platform.IsPlatform)
                {
                    RectangleF intersection = RectangleF.Intersect(platform.Rect, this.Rect);
                    if (intersection.IsEmptyWithTolerance())
                        continue;

                    if (platform.Rect.Bottom < this.Rect.Bottom)
                    {
                        if (MoveY > 0.0f)
                            MoveY = 0.0f;

                        game.MoveWorld(0.0f, -intersection.Height);
                        isColliding = true;
                    }
                    else if (MoveY < 0.0f)
                    {
                        if (platform.Rect.Top > this.Rect.Bottom - tolerance + MoveY)
                        {
                            MoveY = 0.0f;
                            jumping = false;
                            game.MoveWorld(0.0f, intersection.Height);
                            isColliding = true;
                        }
                    }
                    else if (platform.Rect.Top > this.Rect.Bottom - tolerance + MoveY)
                    {
                        jumping = false;
                        game.MoveWorld(0.0f, intersection.Height);
                        isColliding = true;
                    }
                }
            }

            return isColliding;
        }
        public void Update(FPGameProtocol game)
        {
            PointF inputAcceleration = game.InputAcceleration;
            bool moveLeftOrRight = false;

            if (SpeedUpCounter > 0)
            {
                if (++SpeedUpCounter > maxSpeedUpCount)
                {
                    SpeedUpCounter = 0;
                }
            }

            float currentMaxSpeed = SpeedUpCounter > 0 ? maxSpeed * speedPowerUp : maxSpeed;

            if (inputAcceleration.X < 0.0f)
            {
                if (MoveX < 0.0f)
                    MoveX += Math.Abs(inputAcceleration.X) * acceleration * changeDirectionSpeed;
                MoveX += Math.Abs(inputAcceleration.X) * acceleration;
                if (MoveX > currentMaxSpeed)
                    MoveX = currentMaxSpeed;

                moveLeftOrRight = true;
            }
            else if (inputAcceleration.X > 0.0f)
            {
                if (MoveX > 0.0f)
                    MoveX -= Math.Abs(inputAcceleration.X) * acceleration * changeDirectionSpeed;
                MoveX -= Math.Abs(inputAcceleration.X) * acceleration;
                if (MoveX < -currentMaxSpeed)
                    MoveX = -currentMaxSpeed;

                moveLeftOrRight = true;
            }

            if (!jumping && inputAcceleration.Y > 0.0f)
            {
                if (MoveY < upSpeed)
                    MoveY = upSpeed;
                jumping = true;
            }

            if (!moveLeftOrRight)
            {
                if (Math.Abs(MoveX) < deceleration)
                    MoveX = 0.0f;
                else if (MoveX > 0.0f)
                    MoveX -= deceleration;
                else if (MoveX < 0.0f)
                    MoveX += deceleration;
            }

            MoveY -= deceleration;
            if (MoveY < maxFallSpeed)
                MoveY = maxFallSpeed;
            jumping = true;

            game.MoveWorld(MoveX, 0.0f);
            if (CollisionLeftRight(game))
                MoveX = 0.0f;
            game.MoveWorld(0.0f, MoveY);
            CollisionUpDown(game);
            Rotation -= MoveX * 3.0f;

            Alpha += 0.07f;
            if (Alpha > (float)Math.PI)
                Alpha -= (float)Math.PI;
        }
        public bool CollisionLeftRight(FPGameProtocol game)
        {
            bool isColliding = false;

            foreach (var platform in game.GameObjects)
            {
                if (platform.IsPlatform)
                {
                    RectangleF intersection = RectangleF.Intersect(platform.Rect, this.Rect);
                    if (intersection.IsEmptyWithTolerance())
                        continue;

                    if (platform.Rect.Left > this.Rect.Left)
                    {
                        if (platform.IsMovable)
                        {
                            var movable = (FPMovablePlatform)platform;
                            platform.Move(intersection.Width, 0.0f);
                            if (movable.CollisionLeftRight(game))
                            {
                                platform.Move(-intersection.Width, 0.0f);
                                game.MoveWorld(intersection.Width, 0.0f);
                                isColliding = true;
                            }
                        }
                        else
                        {
                            game.MoveWorld(intersection.Width, 0.0f);
                            isColliding = true;
                        }
                    }
                    else if (platform.Rect.Right < this.Rect.Right)
                    {
                        if (platform.IsMovable)
                        {
                            var movable = (FPMovablePlatform)platform;
                            platform.Move(-intersection.Width, 0.0f);
                            if (movable.CollisionLeftRight(game))
                            {
                                platform.Move(intersection.Width, 0.0f);
                                game.MoveWorld(-intersection.Width, 0.0f);
                                isColliding = true;
                            }
                        }
                        else
                        {
                            game.MoveWorld(-intersection.Width, 0.0f);
                            isColliding = true;
                        }
                    }
                }
            }

            return isColliding;
        }