Beispiel #1
0
        /// <summary>
        /// Sets the collision box of the player, and adjusts the immediate position to compensate.
        /// </summary>
        /// <param name="box">The new collision box of the player.</param>
        public void SetBoundingBox(BoundingBox box)
        {
            var oldSize = CollisionBox.GetSize();

            CollisionBox = box;
            var newSize = CollisionBox.GetSize();

            // adjust ground position to compensate for size change
            switch (_moveController.MovementMode)
            {
            case PlayerMovementMode.Floor:
                Position = new Point(Position.X, Position.Y + (oldSize.Y - newSize.Y) / 2);
                break;

            case PlayerMovementMode.Ceiling:
                Position = new Point(Position.X, Position.Y - (oldSize.Y - oldSize.Y) / 2);
                break;

            case PlayerMovementMode.LeftWall:
                Position = new Point(Position.X - (oldSize.Y - newSize.Y) / 2, Position.Y);
                break;

            case PlayerMovementMode.RightWall:
                Position = new Point(Position.X + (oldSize.Y - newSize.Y) / 2, Position.Y);
                break;
            }
        }