Ballz.GameSession.World.Terrain.Terrain C# (CSharp) Метод

Terrain() публичный Метод

public Terrain ( Microsoft.Xna.Framework.Graphics.Texture2D terrainTexture ) : Microsoft.Xna.Framework
terrainTexture Microsoft.Xna.Framework.Graphics.Texture2D
Результат Microsoft.Xna.Framework
        public Terrain(Texture2D terrainTexture)
        {
            terrainData = terrainTexture;

            width = terrainData.Width;
            height = terrainData.Height;

            PublicShape.TerrainBitmap = new TerrainType[width, height];
            terrainSmoothmap = new float[width, height];
            terrainSmoothmapCopy = new float[width, height];
            WaterSpawnBitmap = new bool[width, height];

            Color[] pixels = new Color[width * height];
            terrainData.GetData<Color>(pixels);
            
            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    Color curPixel = pixels[y * width + x];

                    // Note that we flip the y coord here
                    if (curPixel == new Color(127, 64, 0))
                    {
                        PublicShape.TerrainBitmap[x, height - y - 1] = TerrainType.Earth;
                        terrainSmoothmap[x, height - y - 1] = 1.0f;
                    }
                    else if (curPixel == new Color(127, 127, 127))
                    {
                        PublicShape.TerrainBitmap[x, height - y - 1] = TerrainType.Stone;
                    }
                    else if (curPixel == Color.Yellow)
                    {
                        PublicShape.TerrainBitmap[x, height - y - 1] = TerrainType.Sand;
                    }
                    else if (curPixel == Color.Blue)
                    {
                        WaterSpawnBitmap[x, height - y - 1] = true;
                        PublicShape.TerrainBitmap[x, height - y - 1] = TerrainType.Water;
                    }
                    else if (curPixel == Color.Lime)
                    {
                        PublicShape.TerrainBitmap[x, height - y - 1] = TerrainType.VegetationSeed;
                    }
                    else if (curPixel == Color.Red)
                    {
                        PublicShape.TerrainBitmap[x, height - y - 1] = TerrainType.SpawnPoint;
                    }
                }
            }

            // Pre-allocate internal members
            bordersH = new Border[width, height];
            bordersV = new Border[width, height];
            fullCells = new List<List<IntVector2>>(height);
            allEdges = new List<Edge>();

            // Let sand fall down
            UpdateTerrain(0, 0, width);

            Update();
        }