Example #1
0
        private List <Vector2> CreatePointOnBounds(int amount)
        {
            WeightedList <WeightedElement <Directions>, Directions> borderWeights = new WeightedList <WeightedElement <Directions>, Directions>();

            // Add 8 valid directions to the weighted list. For now 8 streets max are possible
            borderWeights.Add(new WeightedElement <Directions>(Directions.North, 1));
            borderWeights.Add(new WeightedElement <Directions>(Directions.East, 1));
            borderWeights.Add(new WeightedElement <Directions>(Directions.South, 1));
            borderWeights.Add(new WeightedElement <Directions>(Directions.West, 1));
            borderWeights.Add(new WeightedElement <Directions>(Directions.North, 1));
            borderWeights.Add(new WeightedElement <Directions>(Directions.East, 1));
            borderWeights.Add(new WeightedElement <Directions>(Directions.South, 1));
            borderWeights.Add(new WeightedElement <Directions>(Directions.West, 1));

            List <Vector2> pointOnBounds = new List <Vector2>();

            for (int i = 0; i < amount; i++)
            {
                var rnd       = FloatGenerator.Generate();
                var direction = borderWeights.GetElement(rnd);

                var rnd1 = FloatGenerator.Generate();

                switch (direction)
                {
                case Directions.North:
                    pointOnBounds.Add(new Vector2(rnd1, 1f));
                    break;

                case Directions.East:
                    pointOnBounds.Add(new Vector2(1f, rnd1));

                    break;

                case Directions.South:
                    pointOnBounds.Add(new Vector2(rnd1, 0f));

                    break;

                case Directions.West:
                    pointOnBounds.Add(new Vector2(0f, rnd1));
                    break;
                }
            }
            return(pointOnBounds);
        }