Time for action – randomly positioning the cube
1. Add the following declaration to the
Fields
region of theC
ube
class:private Random rand = new Random();
2. Replace the current
PositionCube()
method in theCube
class with the following:public void PositionCube(Vector3 playerLocation, float minDistance) { Vector3 newLocation; do { newLocation = new Vector3( rand.Next(0, Maze.mazeWidth) + 0.5f, 0.5f, rand.Next(0, Maze.mazeHeight) + 0.5f); } while ( Vector3.Distance(playerLocation, newLocation) < minDistance); location = newLocation; }
3. In the
Draw()
method of theMaze
class, add the following to the top of the method to make sure we have the correct current settings for our effect, now that we are also using textures:effect.TextureEnabled = false;
4. In the
Draw()
method of theCubeChaserGame
class, uncomment the line that draws the maze by removing the two slashes (//
) from the front of the line.5. Execute...