static void make_natural_cave(int x, int y) { System.Random rnd = new System.Random(); int room_size = 10; int x1 = rnd.Next(5, 1 + room_size / 2); int x2 = rnd.Next(5, 1 + room_size / 2); int y1 = rnd.Next(2, room_size / 2); int y2 = rnd.Next(2, room_size / 2); for (int j = x; j < x + x1; j++) { for (int i = y - y2; i < y + y1; i++) { remove_block(j, i, 0); } List <float> chances = new List <float>() { 1 - (x - j), 6 - 4 * (x - j), 4, 6, 1 }; y1 += Math_lib.choose_random_from_weight_list(chances) - 2; y2 += Math_lib.choose_random_from_weight_list(chances) - 2; if (y1 <= 0) { y1 = 1; } if (y2 < 0) { y2 = 1; } } for (int j = x; j > x - x1; j--) { for (int i = y - y2; i < y + y1; i++) { remove_block(j, i, 0); } List <float> chances = new List <float>() { 1 + (x - j), 6 + 4 * (x - j), 4, 6, 1 }; y1 += Math_lib.choose_random_from_weight_list(chances) - 2; y2 += Math_lib.choose_random_from_weight_list(chances) - 2; if (y1 <= 0) { y1 = 1; } if (y2 < 0) { y2 = 1; } } }
public static List <Vector2> worm(int length, int x_start, int y_start, List <float> chances_of_every_direction) { List <Vector2> dots = new List <Vector2>() { new Vector2(x_start, y_start) }; int x = x_start; int y = y_start; int dir = 0; int prev_dir = 0; for (int i = 0; i < length; i++) { while (dir == prev_dir) { dir = Math_lib.choose_random_from_weight_list(chances_of_every_direction); } if (dir == 0) { y++; } else if (dir == 1) { x++; } else if (dir == 2) { y--; } else if (dir == 3) { x--; } prev_dir = dir; Debug.Log("worm" + dir + " " + x + "," + y); dots.Add(new Vector2(x, y)); } return(dots); }