public override void OnInspectorGUI() { DrawDefaultInspector(); CaveGeneration generationScript = (CaveGeneration)target; if (GUILayout.Button("Generate Terrain")) { generationScript.Generate(); } }
public override void OnInspectorGUI() { DrawDefaultInspector(); CaveGeneration myScript = (CaveGeneration)target; if (GUILayout.Button("Make Map")) { myScript.MakeMap(); } }
/// <summary> /// Creates a map based on the requested algorithm. /// </summary> public void GenerateMap(AlgorithmType algorithm, int seed) { switch (algorithm) { case AlgorithmType.Hills: // Use the case relevant to your algorithm type // Create the appropriate algorithm, inputing your personal variables from LevelVariables as shown in the algorithms information. if (true) // Neccessary to use the same names for variables. { HillGeneration hillGen = new HillGeneration(terrain, LevelVariables.WIDTH, LevelVariables.HEIGHT, LevelVariables.GROUND_HEIGHT, LevelVariables.SAFE_ZONE_WIDTH, LevelVariables.HILL_MIN_WIDTH, LevelVariables.HILL_MAX_WIDTH, LevelVariables.HILL_MIN_HEIGHT, LevelVariables.HILL_MAX_HEIGHT, LevelVariables.HILL_SMOOTH_WIDTH, LevelVariables.HILL_VARIATION, LevelVariables.HILL_PEAK_AVERAGE_PERCENT, seed); hillGen.Initialize(); // Run the initialization code. hillGen.Shape(); // Run the shaping code this.terrain = hillGen.Terrain; // Save the terrain changes. // Here I would add the next algorithm if this was a complex algorithm type. int numberOfPoints = rand.Next(LevelVariables.CAVE_MIN_POINTS, LevelVariables.CAVE_MAX_POINTS); List <int[]> points = new List <int[]>(); //for (int m = 0; m <= numberOfPoints; m++) //{ // // Create points for the caves to go in, but make sure that they don't leave the map. // points.Add(new int[3]{ // rand.Next(LevelVariables.CAVE_MAX_RADIUS + 1, LevelVariables.WIDTH - LevelVariables.CAVE_MAX_RADIUS), // rand.Next(LevelVariables.CAVE_MAX_RADIUS + 1, LevelVariables.HEIGHT - LevelVariables.CAVE_MAX_RADIUS), // rand.Next(LevelVariables.CAVE_MIN_RADIUS, LevelVariables.CAVE_MAX_RADIUS)}); //} // Create the caves for (int m = 0; m <= numberOfPoints; m++) { // Create points for the tunnels. points.Add(new int[3] { (LevelVariables.WIDTH / numberOfPoints) * m, LevelVariables.GROUND_HEIGHT + rand.Next(-7, 7) + 10, 0 }); } CaveGeneration caveGen = new CaveGeneration(terrain, points, LevelVariables.WIDTH, LevelVariables.HEIGHT, LevelVariables.GROUND_HEIGHT, LevelVariables.SAFE_ZONE_WIDTH, seed); //caveGen.Shape(); caveGen.Tunnel(2); } break; case AlgorithmType.Desert: // Use the case relevant to your algorithm type if (true) { // Create the appropriate algorithm, inputing your personal variables from LevelVariables as shown in the algorithms information. HillGeneration desertGen = new HillGeneration(terrain, LevelVariables.WIDTH, LevelVariables.HEIGHT, LevelVariables.GROUND_HEIGHT, LevelVariables.SAFE_ZONE_WIDTH, LevelVariables.DESERT_MIN_WIDTH, LevelVariables.DESERT_MAX_WIDTH, LevelVariables.DESERT_MIN_HEIGHT, LevelVariables.DESERT_MAX_HEIGHT, LevelVariables.DESERT_SMOOTH_WIDTH, LevelVariables.DESERT_VARIATION, LevelVariables.DESERT_PEAK_AVERAGE_PERCENT, seed); desertGen.Initialize(); // Run the initialization code. desertGen.Shape(); // Run the shaping code this.terrain = desertGen.Terrain; // Save the terrain changes. } // Here I would add the next algorithm if this was a complex algorithm type. break; case AlgorithmType.HillsDesert: // Example Complex Algorithm if (true) { // Create the appropriate algorithm, inputing your personal variables from LevelVariables as shown in the algorithms information. HillGeneration hillGen = new HillGeneration(terrain, LevelVariables.WIDTH, LevelVariables.HEIGHT, LevelVariables.GROUND_HEIGHT, LevelVariables.SAFE_ZONE_WIDTH, LevelVariables.HILL_MIN_WIDTH, LevelVariables.HILL_MAX_WIDTH, LevelVariables.HILL_MIN_HEIGHT, LevelVariables.HILL_MAX_HEIGHT, LevelVariables.HILL_SMOOTH_WIDTH, LevelVariables.HILL_VARIATION, LevelVariables.HILL_PEAK_AVERAGE_PERCENT, seed); hillGen.Initialize(0, LevelVariables.WIDTH / 2, 0, LevelVariables.HEIGHT); // Run the initialization code. hillGen.Shape(0, LevelVariables.WIDTH / 2, 0, LevelVariables.HEIGHT); // Run the shaping code this.terrain = hillGen.Terrain; // Save the terrain changes. } if (true) { // Create the appropriate algorithm, inputing your personal variables from LevelVariables as shown in the algorithms information. HillGeneration desertGen = new HillGeneration(terrain, LevelVariables.WIDTH, LevelVariables.HEIGHT, LevelVariables.GROUND_HEIGHT, LevelVariables.SAFE_ZONE_WIDTH, LevelVariables.DESERT_MIN_WIDTH, LevelVariables.DESERT_MAX_WIDTH, LevelVariables.DESERT_MIN_HEIGHT, LevelVariables.DESERT_MAX_HEIGHT, LevelVariables.DESERT_SMOOTH_WIDTH, LevelVariables.DESERT_VARIATION, LevelVariables.DESERT_PEAK_AVERAGE_PERCENT, seed); desertGen.Initialize(LevelVariables.WIDTH / 2, LevelVariables.WIDTH, 0, LevelVariables.HEIGHT); // Run the initialization code. desertGen.Shape(LevelVariables.WIDTH / 2, LevelVariables.WIDTH, 0, LevelVariables.HEIGHT); // Run the shaping code this.terrain = desertGen.Terrain; // Save the terrain changes. } if (true) { // Let's just apply caves EVERYWHERE! int numberOfPoints = rand.Next(LevelVariables.CAVE_MIN_POINTS, LevelVariables.CAVE_MAX_POINTS); List <int[]> points = new List <int[]>(); //for (int m = 0; m <= numberOfPoints; m++) //{ // // Create points for the caves to go in, but make sure that they don't leave the map. // points.Add(new int[3]{ // rand.Next(LevelVariables.CAVE_MAX_RADIUS + 1, LevelVariables.WIDTH - LevelVariables.CAVE_MAX_RADIUS), // rand.Next(LevelVariables.CAVE_MAX_RADIUS + 1, LevelVariables.HEIGHT - LevelVariables.CAVE_MAX_RADIUS), // rand.Next(LevelVariables.CAVE_MIN_RADIUS, LevelVariables.CAVE_MAX_RADIUS)}); //} // Create the caves for (int m = 0; m <= numberOfPoints; m++) { // Create points for the tunnels. points.Add(new int[3] { (LevelVariables.WIDTH / numberOfPoints) * m, LevelVariables.GROUND_HEIGHT + rand.Next(-7, 7) + 10, 0 }); } CaveGeneration caveGen = new CaveGeneration(terrain, points, LevelVariables.WIDTH, LevelVariables.HEIGHT, LevelVariables.GROUND_HEIGHT, LevelVariables.SAFE_ZONE_WIDTH, seed); //caveGen.Shape(); caveGen.Tunnel(2); } break; case AlgorithmType.Cave: if (true) { int numberOfPoints = rand.Next(LevelVariables.CAVE_MIN_POINTS, LevelVariables.CAVE_MAX_POINTS); List <int[]> points = new List <int[]>(); int safeRadius = rand.Next(LevelVariables.CAVE_MIN_RADIUS, LevelVariables.CAVE_MAX_RADIUS); points.Add(new int[3] { 5, LevelVariables.GROUND_HEIGHT, safeRadius }); for (int m = 1; m < numberOfPoints; m++) { // Create points for the caves to go in, but make sure that they don't leave the map. points.Add(new int[3] { rand.Next(LevelVariables.CAVE_MAX_RADIUS + 1, LevelVariables.WIDTH - LevelVariables.CAVE_MAX_RADIUS), rand.Next(LevelVariables.CAVE_MAX_RADIUS + 1, LevelVariables.HEIGHT - LevelVariables.CAVE_MAX_RADIUS), rand.Next(LevelVariables.CAVE_MIN_RADIUS, LevelVariables.CAVE_MAX_RADIUS) }); } points.Add(new int[3] { LevelVariables.WIDTH - 8, LevelVariables.GROUND_HEIGHT, safeRadius }); // Create the caves CaveGeneration caveGen = new CaveGeneration(terrain, points, LevelVariables.WIDTH, LevelVariables.HEIGHT, LevelVariables.GROUND_HEIGHT, LevelVariables.SAFE_ZONE_WIDTH, seed); caveGen.Initialize(); caveGen.Shape(); // Create a safe spawning zone caveGen.Initialize(0, 5 + safeRadius, 0, LevelVariables.GROUND_HEIGHT - 2); caveGen.Initialize(LevelVariables.WIDTH - (8 + safeRadius), LevelVariables.WIDTH, 0, LevelVariables.GROUND_HEIGHT); caveGen.Tunnel(2); caveGen.Initialize(0, 1, 0, LevelVariables.HEIGHT); caveGen.Initialize(LevelVariables.WIDTH - 2, LevelVariables.WIDTH - 1, 0, LevelVariables.HEIGHT); } break; } }