void GenPrefabMaze() { if (MapConfig != null) { mazeGen.RemoveDeadEndsIterations = MapConfig.RemoveDeadEndsIterations; mazeGen.DeadCells = MapConfig.DeadCells; mazeGen.loopPercent = MapConfig.loopPercent; mazeGen.windyOrRandomPercent = MapConfig.windyOrRandomPercent; mazeGen.Visited = new bool[MapConfig.width, MapConfig.height]; mapData.width = MapConfig.width; mapData.height = MapConfig.height; mapData.Map = new int[MapConfig.width, MapConfig.height]; MaxLargeRooms = MapConfig.MaxLargeRooms; Items = MapConfig.Items; } mapsGenerated++; if (mapData.LargeRoomPositions == null) { mapData.LargeRoomPositions = new List <MapPos>(); } else { mapData.LargeRoomPositions.Clear(); } getFiles(); mazeGen.Generate(mapData.RandomEven(0, mapData.width - 1), mapData.RandomEven(0, mapData.height - 1)); InitLargeRooms(); CutExcessLargeRooms(); // dead ends are a problem in maps that can contain nothing but loops. (StackOverflow Exception) // they suck as a starting location. usefull for and end location. if (mazeGen.DeadEnds.Count != 0) { //start/end location wont allways spawn now because there isnt always dead ends. GameObject player = GameObject.FindGameObjectWithTag("Player"); GameObject cam = GameObject.FindGameObjectWithTag("MainCamera"); StartPos = mazeGen.DeadEnds[mapData.RandomEven(0, mazeGen.DeadEnds.Count - 1)]; print("Start Pos: " + StartPos.ToString()); findmapend(StartPos); player.transform.position = new Vector3((((StartPos.x * MapData.ROOMWIDTH) / 2) + (MapData.ROOMWIDTH / 2)), (((StartPos.y * MapData.ROOMHEIGHT) / 2) - (MapData.ROOMHEIGHT / 2)), 0); cam.transform.position = new Vector3((((StartPos.x * MapData.ROOMWIDTH) / 2) + (MapData.ROOMWIDTH / 2)), (((StartPos.y * MapData.ROOMHEIGHT) / 2) - (MapData.ROOMHEIGHT / 2)), -10); } else { if (mapsGenerated < 10) { GenPrefabMaze(); } } GenPrefabs(); }
MapPos findmapend(MapPos startpos) { MapPos f = new MapPos(-1, -1); MapPos endPos = f; int endDist = 0; foreach (MapPos deadend in mazeGen.DeadEnds) { int newdist = (int)Mathf.Abs(startpos.x - deadend.x) + (int)Mathf.Abs(startpos.y - deadend.y); if (endPos.Equals(f) || endDist < newdist) { endPos = deadend; endDist = newdist; } } print("End Pos: " + endPos.ToString()); print("Dist to End: " + endDist.ToString()); return(endPos); }