Ballz.SessionFactory.TerrainGenerator.GenerateTerrain C# (CSharp) Method

GenerateTerrain() public static method

public static GenerateTerrain ( int width, int height ) : Microsoft.Xna.Framework.Graphics.Texture2D
width int
height int
return Microsoft.Xna.Framework.Graphics.Texture2D
        public static Texture2D GenerateTerrain(int width, int height)
        {
            var types = GenerateArray(width, height);

            var typeData = types.Cast<Terrain.TerrainType>();

            var colorData = typeData.Select(t => {
                switch (t)
                {
                    case Terrain.TerrainType.Air:
                        return Color.Black;
                    case Terrain.TerrainType.Earth:
                        return new Color(127, 64, 0);
                    case Terrain.TerrainType.Stone:
                        return new Color(127, 127, 127);
                    case Terrain.TerrainType.Sand:
                        return Color.Yellow;
                    case Terrain.TerrainType.Water:
                        return Color.Blue;
                    case Terrain.TerrainType.VegetationSeed:
                        return Color.Lime;
                    case Terrain.TerrainType.SpawnPoint:
                        return Color.Red;
                    default:
                        throw new ArgumentOutOfRangeException(nameof(t), t, null);
                }
            });

            var t2D = new Texture2D(Ballz.The().GraphicsDevice, width, height);
            t2D.SetData(colorData.ToArray());

            return t2D;
        }

Usage Example

Example #1
0
        protected override void ImplInitializeSession(Ballz game, MatchSettings settings)
        {
            var mapTexture = MapName == "Generated" ? TerrainGenerator.GenerateTerrain(width, height): game.Content.Load <Texture2D>("Worlds/" + MapName);

            settings.MapName    = MapName;
            settings.MapTexture = mapTexture;
        }