Time for action – generating the terrain
1. Add a new class to the Tank Battles project by right-clicking on the project in Solution Explorer and selecting Add | Class....
2. Ensure that the Visual C# | Code is selected under Installed Templates and select the Class template.
3. Enter
Terrain.cs
as the name of the class file.4. Add the following
using
directive to the top of theTerrain.cs
file:using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics;
5. Add the following fields to the
Terrain
class:#region Fields private VertexBuffer vertexBuffer; private IndexBuffer indexBuffer; private GraphicsDevice device; private Texture2D terrainTexture; private float textureScale; private float[,] heights; #endregion
6. Add a constructor to the
Terrain
class:#region Constructor public Terrain( GraphicsDevice graphicsDevice, Texture2D heightMap, Texture2D terrainTexture, float textureScale, int terrainWidth, int terrainHeight, float heightScale) { device...