void Awake() { PrimGenerator primGen = new PrimGenerator(); // generate a map of size 20x20 with no extra walls removed MapTile[,] tiles1 = primGen.MapGen(maxX, maxY, 0.3f); PerlinGenerator perlinGen = new PerlinGenerator(); // generates a map of size 20x20 with a large constraint (generates a tightly-packed map) map = perlinGen.MapGen(maxX, maxY, 5.0f); GameObject playerAI = Instantiate(player, new Vector3(0, 0, -.5f), Quaternion.identity); GameObject enemyAI1 = Instantiate(enemy1, new Vector3(0, 0, -.5f), Quaternion.identity); playerAI.GetComponent <playerScript>().map = map; //enemy1.GetComponent<enemyScript>().map = tiles3; walkables = new List <MapTile>(); foreach (MapTile m in map) { if (m.Walkable) { walkables.Add(m); } } foreach (MapTile m in map) { Vector3 pos = new Vector3(m.X + transform.position.x, m.Y + transform.position.y); int walkableint = walkables.Count; System.Random rnd = new System.Random(); int rndnum = rnd.Next(0, walkableint - 1); if (m.IsStart) { Instantiate(startTile, pos, Quaternion.identity); playerAI.transform.position = new Vector3(m.X + transform.position.x, m.Y + transform.position.y, -.5f); playerAI.GetComponent <playerScript>().xMax = maxX; playerAI.GetComponent <playerScript>().yMax = maxY; playerAI.GetComponent <playerScript>().start = m; } else if (m.IsGoal) { Instantiate(goalTile, pos, Quaternion.identity); playerAI.GetComponent <playerScript>().goal = m; } else if (m.Walkable) { Instantiate(yesTile, pos, Quaternion.identity); if (m == walkables[rndnum]) { enemyAI1.transform.position = new Vector3(m.X + transform.position.x, m.Y + transform.position.y, -.5f); } } else if (!m.Walkable) { Instantiate(noTile, pos, Quaternion.identity); } } }
void Awake() { prim = new PrimGenerator(); perlin = new PerlinGenerator(); // generate a map of size 30x30 with half of the walls removed after generation if (primOrPerlin == "Prim" || primOrPerlin == "prim") tiles = prim.MapGen(dimension, dimension, removOrConstrain); else tiles = perlin.MapGen(dimension, dimension, removOrConstrain); }
void Start() { PrimGenerator primGen = new PrimGenerator(); // generate a map of size 20x20 with no extra walls removed MapTile[,] tiles1 = primGen.MapGen(20, 20, 0.0f); // generate a map of size 30x30 with half of the walls removed after generation MapTile[,] tiles2 = primGen.MapGen(30, 30, 0.5f); PerlinGenerator perlinGen = new PerlinGenerator(); // generates a map of size 20x20 with a large constraint (generates a tightly-packed map) MapTile[,] tiles3 = perlinGen.MapGen(20, 20, 5.0f); // generates a map of size 20x20 with a medium constraint (generates a more open map) MapTile[,] tiles4 = perlinGen.MapGen(20, 20, 10.0f); // generates a map of size 20x20 with a small constraint (generates a very open map) MapTile[,] tiles5 = perlinGen.MapGen(20, 20, 20.0f); }
MapTile[,] generateTilesList() { MapTile[,] tiles; if (perlinGenerator) { PerlinGenerator perlinGen = new PerlinGenerator(); tiles = perlinGen.MapGen(width, height, perlinConstraint); } else { PrimGenerator primGen = new PrimGenerator(); tiles = primGen.MapGen(width, height, primeConstraint); } return(tiles); }
void createM() { PrimGenerator primGen = new PrimGenerator(); // generate a map of size 20x20 with no extra walls removed tiles4 = primGen.MapGen(75, 75, 0.05f); foreach (MapTile a in tiles4) { if (a.IsGoal) { Instantiate(goalPlane, new Vector3(a.X, 0, a.Y), Quaternion.identity); } else if (a.IsStart) { Instantiate(startPlane, new Vector3(a.X, 0, a.Y), Quaternion.identity); Instantiate(pc, new Vector3(a.X, .5f, a.Y), Quaternion.identity); } else if (a.Walkable) { Instantiate(walkable, new Vector3(a.X, 0, a.Y), Quaternion.identity); } else { Instantiate(notWalkable, new Vector3(a.X, 1, a.Y), Quaternion.identity); } } foreach (MapTile a in tiles4) { if (a.Walkable) { int chance = Mathf.RoundToInt(Random.Range(.5f, 500.5f)); if (chance == 1) { Instantiate(enemy1, new Vector3(a.X, .5f, a.Y), Quaternion.identity); } } } }
void Start() { PrimGenerator primGen = new PrimGenerator(); PerlinGenerator perlinGen = new PerlinGenerator(); switch (choice) { case 1: // generate a map of size 20x20 with no extra walls removed MapTile[,] tiles1 = primGen.MapGen(20, 20, 0.25f); for (int i = 0; i < 20; i++) { for (int y = 0; y < 20; y++) { if (tiles1[i, y].Walkable == true) { if (tiles1[i, y].IsStart) { Instantiate(start, new Vector3(tiles1[i, y].X, .005f, tiles1[i, y].Y), Quaternion.identity); } else if (tiles1[i, y].IsGoal) { Instantiate(goal, new Vector3(tiles1[i, y].X, .005f, tiles1[i, y].Y), Quaternion.identity); } else { Instantiate(floor, new Vector3(tiles1[i, y].X, .005f, tiles1[i, y].Y), Quaternion.identity); } } else { Instantiate(wall, new Vector3(tiles1[i, y].X, 1, tiles1[i, y].Y), Quaternion.identity); } } } break; case 2: // generate a map of size 30x30 with half of the walls removed after generation MapTile[,] tiles2 = primGen.MapGen(30, 30, 0.15f); for (int i = 0; i < 30; i++) { for (int y = 0; y < 30; y++) { if (tiles2[i, y].Walkable == true) { if (tiles2[i, y].IsStart) { Instantiate(start, new Vector3(tiles2[i, y].X, .005f, tiles2[i, y].Y), Quaternion.identity); } else if (tiles2[i, y].IsGoal) { Instantiate(goal, new Vector3(tiles2[i, y].X, .005f, tiles2[i, y].Y), Quaternion.identity); } else { Instantiate(floor, new Vector3(tiles2[i, y].X, .005f, tiles2[i, y].Y), Quaternion.identity); } } else { Instantiate(wall, new Vector3(tiles2[i, y].X, 1, tiles2[i, y].Y), Quaternion.identity); } } } break; case 3: // generates a map of size 20x20 with a large constraint (generates a tightly-packed map) MapTile[,] tiles3 = perlinGen.MapGen(20, 20, 5.0f); for (int i = 0; i < 20; i++) { for (int y = 0; y < 20; y++) { if (tiles3[i, y].Walkable == true) { if (tiles3[i, y].IsStart) { Instantiate(start, new Vector3(tiles3[i, y].X, .005f, tiles3[i, y].Y), Quaternion.identity); } else if (tiles3[i, y].IsGoal) { Instantiate(goal, new Vector3(tiles3[i, y].X, .005f, tiles3[i, y].Y), Quaternion.identity); } else { Instantiate(floor, new Vector3(tiles3[i, y].X, .005f, tiles3[i, y].Y), Quaternion.identity); } } else { Instantiate(wall, new Vector3(tiles3[i, y].X, 1, tiles3[i, y].Y), Quaternion.identity); } } } break; case 4: // generates a map of size 20x20 with a medium constraint (generates a more open map) MapTile[,] tiles4 = perlinGen.MapGen(20, 20, 10.0f); for (int i = 0; i < 20; i++) { for (int y = 0; y < 20; y++) { if (tiles4[i, y].Walkable == true) { if (tiles4[i, y].IsStart) { Instantiate(start, new Vector3(tiles4[i, y].X, .005f, tiles4[i, y].Y), Quaternion.identity); } else if (tiles4[i, y].IsGoal) { Instantiate(goal, new Vector3(tiles4[i, y].X, .005f, tiles4[i, y].Y), Quaternion.identity); } else { Instantiate(floor, new Vector3(tiles4[i, y].X, .005f, tiles4[i, y].Y), Quaternion.identity); } } else { Instantiate(wall, new Vector3(tiles4[i, y].X, 1, tiles4[i, y].Y), Quaternion.identity); } } } break; case 5: // generates a map of size 20x20 with a small constraint (generates a very open map) MapTile[,] tiles5 = perlinGen.MapGen(20, 20, 20.0f); for (int i = 0; i < 20; i++) { for (int y = 0; y < 20; y++) { if (tiles5[i, y].Walkable == true) { if (tiles5[i, y].IsStart) { Instantiate(start, new Vector3(tiles5[i, y].X, .005f, tiles5[i, y].Y), Quaternion.identity); } else if (tiles5[i, y].IsGoal) { Instantiate(goal, new Vector3(tiles5[i, y].X, .005f, tiles5[i, y].Y), Quaternion.identity); } else { Instantiate(floor, new Vector3(tiles5[i, y].X, .005f, tiles5[i, y].Y), Quaternion.identity); } } else { Instantiate(wall, new Vector3(tiles5[i, y].X, 1, tiles5[i, y].Y), Quaternion.identity); } } } break; } }