Esempio n. 1
0
        private Point FindSharpTearsSpot(Vector2 origin, Vector2 targetSpot)
        {
            targetSpot.ToTileCoordinates();
            Vector2 center        = origin;
            Vector2 endPoint      = targetSpot;
            int     samplesToTake = 3;
            float   samplingWidth = 4f;
            Vector2 vectorTowardsTarget;

            float[] samples;
            Collision.AimingLaserScan(center, endPoint, samplingWidth, samplesToTake, out vectorTowardsTarget, out samples);
            float num = float.PositiveInfinity;

            for (int index = 0; index < samples.Length; ++index)
            {
                if ((double)samples[index] < (double)num)
                {
                    num = samples[index];
                }
            }
            targetSpot = center + vectorTowardsTarget.SafeNormalize(Vector2.Zero) * num;
            Point tileCoordinates = targetSpot.ToTileCoordinates();

            Microsoft.Xna.Framework.Rectangle rectangle1 = new Microsoft.Xna.Framework.Rectangle(tileCoordinates.X, tileCoordinates.Y, 1, 1);
            rectangle1.Inflate(6, 16);
            Microsoft.Xna.Framework.Rectangle rectangle2 = new Microsoft.Xna.Framework.Rectangle(0, 0, Main.maxTilesX, Main.maxTilesY);
            rectangle2.Inflate(-40, -40);
            rectangle1 = Microsoft.Xna.Framework.Rectangle.Intersect(rectangle1, rectangle2);
            List <Point> pointList1 = new List <Point>();
            List <Point> pointList2 = new List <Point>();

            for (int left = rectangle1.Left; left <= rectangle1.Right; ++left)
            {
                for (int top = rectangle1.Top; top <= rectangle1.Bottom; ++top)
                {
                    if (WorldGen.SolidTile(left, top))
                    {
                        Vector2 vector2 = new Vector2((float)(left * 16 + 8), (float)(top * 16 + 8));
                        if ((double)Vector2.Distance(targetSpot, vector2) <= 200.0)
                        {
                            if (FindSharpTearsOpening(left, top, left > tileCoordinates.X, left <tileCoordinates.X, top> tileCoordinates.Y, top < tileCoordinates.Y))
                            {
                                pointList1.Add(new Point(left, top));
                            }
                            else
                            {
                                pointList2.Add(new Point(left, top));
                            }
                        }
                    }
                }
            }
            if (pointList1.Count == 0 && pointList2.Count == 0)
            {
                pointList1.Add((origin.ToTileCoordinates().ToVector2() + Main.rand.NextVector2Square(-2f, 2f)).ToPoint());
            }
            List <Point> pointList3 = pointList1;

            if (pointList3.Count == 0)
            {
                pointList3 = pointList2;
            }
            int index1 = Main.rand.Next(pointList3.Count);

            return(pointList3[index1]);
        }