Guest User

river

a guest
Feb 3rd, 2024
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. private List<Vector3Int> GetRiverPath(Vector3Int start, Vector3Int end, System.Random random)
  2. {
  3.     List<Vector3Int> path = new();
  4.     Vector3Int current = start;
  5.     path.Add(current);
  6.  
  7.     while (current != end)
  8.     {
  9.         Vector3Int remainingDistance = end - current;
  10.         int k = Sign(remainingDistance.x);
  11.         int l = Sign(remainingDistance.y);
  12.         Vector3Int direction;
  13.         if (k != 0 && l != 0)
  14.         {
  15.             Vector3Int[] directions = new Vector3Int[3] { new Vector3Int(k, 0),
  16.                 new Vector3Int(k, l), new Vector3Int(0, l) };
  17.             direction = directions[random.Next(directions.Length)];
  18.         }
  19.         else
  20.         {
  21.             Vector3Int[] directions = new Vector3Int[3] { new Vector3Int(k + l, k + l),
  22.                 new Vector3Int (k, l), new Vector3Int(k - l, l - k)};
  23.  
  24.             foreach (var dir in directions)
  25.             {
  26.                 if (path.Contains(current + dir))
  27.                 {
  28.                     path.Remove(dir);
  29.                 }
  30.             }
  31.  
  32.             direction = directions[random.Next(directions.Length)];
  33.         }
  34.  
  35.         current += direction;
  36.         path.Add(current);
  37.     }
  38.  
  39.     return path;
  40. }
Add Comment
Please, Sign In to add comment