Exemple #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);
        }