Exemplo n.º 1
0
        private bool[,] GenerateWalkabilityMatrix(int xSize, int ySize)
        {
            var walkability = new bool[xSize, ySize];

            float perlinScale = .5f;

            for (int x = 0; x < xSize; x++)
            {
                for (int y = 0; y < ySize; y++)
                {
                    float xScaled   = x * perlinScale;
                    float yScaled   = y * perlinScale;
                    float threshold = _density == GridDensity.Sparse ? 0.6f : _density == GridDensity.Medium ? 0.55f : 0.5f;

                    float value = _noise.NoiseComplex(xScaled, yScaled);
                    if (value < threshold)
                    {
                        walkability[x, y] = true;
                    }
                }
            }

            if (_hasWalls)
            {
                for (int x = 0; x < xSize; x++)
                {
                    for (int y = 0; y < ySize; y++)
                    {
                        float xScaled = x * perlinScale * 0.08f;
                        float yScaled = y * perlinScale;

                        float value  = _noise.Noise(xScaled, yScaled);
                        float value2 = _noise.Noise(yScaled + 3, xScaled + 42);
                        if (value < 0.3f)
                        {
                            walkability[x, y] = false;
                        }
                        if (value2 < 0.3f)
                        {
                            walkability[y, x] = false;
                        }
                    }
                }
            }

            return(walkability);
        }
Exemplo n.º 2
0
        public void Noise2D_Test()
        {
            var noise = new Noise2D(333);

            float [,] values = new float[100, 100];


            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    values[i, j] = noise.Noise(i, j);
                }
            }
            IDictionary <float, int> widmo = new SortedDictionary <float, int>();

            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    float  val   = values[i, j];
                    string value = val < 0.2f ? " " : val < 0.4f ? "." : val < 0.6f ? ":" : val < 0.8f ? "|" : "#";
                    //Console.Write(value);


                    float przedzial = (float)Math.Ceiling(val * 10) / 10f;
                    if (!widmo.ContainsKey(przedzial))
                    {
                        widmo[przedzial] = 1;
                    }
                    else
                    {
                        ++widmo[przedzial];
                    }
                }
                //Console.Write("\r\n");
            }

            foreach (KeyValuePair <float, int> keyValuePair in widmo)
            {
                Console.WriteLine(keyValuePair.Key + ": " + keyValuePair.Value);
            }
        }