void GenPrefabs() { List <MapPos> Generated = new List <MapPos>(); int prefabX; int prefabY; int mapX = 0; int mapY = 0; for (int y = 0; y < mapData.height; y = y + 2) { for (int x = 0; x < mapData.width; x = x + 2) { MapPos cPos = new MapPos(x, y); if (mapX == (mapData.width / 2) + 1) { mapX = 0; mapY++; } prefabX = mapX * MapData.ROOMWIDTH; prefabY = mapY * MapData.ROOMHEIGHT; GameObject go; if (mapData.LargeRoomPositions.Contains(cPos)) { Generated.AddRange(getLargeRoomPositions(x, y)); go = GenRoom(prefabX, prefabY + MapData.ROOMHEIGHT, _64x64[mapData.Rng.Next(0, _64x64.Count)], true, cPos); CameraZone camZone = go.GetComponent <CameraZone>(); BoxCollider2D camColl = go.GetComponent <BoxCollider2D>(); camZone.zoneWidth = MapData.ROOMWIDTH * 2; camZone.zoneHeight = MapData.ROOMHEIGHT * 2; camColl.size = new Vector2(MapData.ROOMWIDTH * 2, MapData.ROOMHEIGHT * 2); camColl.offset = new Vector2(MapData.ROOMWIDTH, -MapData.ROOMHEIGHT); } else if (mapData.Map[x, y] == 1 && !Generated.Contains(cPos)) { go = GenRoom(prefabX, prefabY, _32x32[mapData.Rng.Next(0, _32x32.Count)], false, cPos); if (cPos.Equals(StartPos)) { CameraZone camZone = go.GetComponent <CameraZone>(); GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CameraController>().curCamZone = camZone; } } mapX++; } } }
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); }