Пример #1
0
        /// <summary>Draw a tracking arrow pointer on the edge of the screen pointing to a target off-screen.</summary>
        /// <param name="target">The target to point to.</param>
        /// <param name="color">The color of the pointer.</param>
        /// <remarks>Note that the game will add a yellow tinge to the color supplied here.</remarks>
        public static void DrawTrackingArrowPointer(Vector2 target, Color color)
        {
            if (SUtility.isOnScreen(target * 64f + new Vector2(32f, 32f), 64))
            {
                return;
            }

            ArrowPointer ??= new ArrowPointer(AwesomeProfessions.Content.Load <Texture2D>(Path.Combine("assets", "cursor.png")));

            var     vpbounds         = Game1.graphics.GraphicsDevice.Viewport.Bounds;
            Vector2 onScreenPosition = default;
            var     rotation         = 0f;

            if (target.X * 64f > Game1.viewport.MaxCorner.X - 64)
            {
                onScreenPosition.X = vpbounds.Right - 8;
                rotation           = (float)Math.PI / 2f;
            }
            else if (target.X * 64f < Game1.viewport.X)
            {
                onScreenPosition.X = 8f;
                rotation           = -(float)Math.PI / 2f;
            }
            else
            {
                onScreenPosition.X = target.X * 64f - Game1.viewport.X;
            }

            if (target.Y * 64f > Game1.viewport.MaxCorner.Y - 64)
            {
                onScreenPosition.Y = vpbounds.Bottom - 8;
                rotation           = (float)Math.PI;
            }
            else if (target.Y * 64f < Game1.viewport.Y)
            {
                onScreenPosition.Y = 8f;
            }
            else
            {
                onScreenPosition.Y = target.Y * 64f - Game1.viewport.Y;
            }

            if ((int)onScreenPosition.X == 8 && (int)onScreenPosition.Y == 8)
            {
                rotation += (float)Math.PI / 4f;
            }

            if ((int)onScreenPosition.X == 8 && (int)onScreenPosition.Y == vpbounds.Bottom - 8)
            {
                rotation += (float)Math.PI / 4f;
            }

            if ((int)onScreenPosition.X == vpbounds.Right - 8 && (int)onScreenPosition.Y == 8)
            {
                rotation -= (float)Math.PI / 4f;
            }

            if ((int)onScreenPosition.X == vpbounds.Right - 8 && (int)onScreenPosition.Y == vpbounds.Bottom - 8)
            {
                rotation -= (float)Math.PI / 4f;
            }

            var srcRect     = new Rectangle(0, 0, 5, 4);
            var renderScale = 4f;
            var safePos     = SUtility.makeSafe(renderSize: new Vector2(srcRect.Width * renderScale, srcRect.Height * renderScale), renderPos: onScreenPosition);

            Game1.spriteBatch.Draw(ArrowPointer.Texture, safePos, srcRect, color, rotation, new Vector2(2f, 2f), renderScale, SpriteEffects.None, 1f);
        }