Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2020
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. internal static GridCell[] FindRequiredCells(GridWorld world, GridCell basecell, CellOccupant occupant)
  2.         {
  3.             GridCell[] cells = null;
  4.  
  5.  
  6.             int XCount = (occupant.SizeX * world.CellSize) / world.CellSize;
  7.             int YCount = (occupant.SizeY * world.CellSize) / world.CellSize;
  8.  
  9.             if (XCount == 1 && YCount == 1)
  10.             {
  11.                 return new GridCell[1] { basecell };
  12.             }
  13.  
  14.             var RequiredGridCount = XCount * YCount;
  15.  
  16.             cells = new GridCell[RequiredGridCount+1];
  17.  
  18.             int RowIndex = -1;
  19.             int ColIndex = 0;
  20.  
  21.             int GridIndex = 0;
  22.  
  23.             for (int i = 0; i < XCount; i++)
  24.             {
  25.                 if (i % XCount == 0)
  26.                 {
  27.                     RowIndex++;
  28.                     ColIndex = 0;
  29.                 }
  30.                 else
  31.                 {
  32.                     ColIndex++;
  33.                 }
  34.                 cells[GridIndex] = world.GetCell(basecell.XIndex + ColIndex, basecell.YIndex);
  35.                 GridIndex++;
  36.             }
  37.  
  38.  
  39.             RowIndex = -1;
  40.             ColIndex = 0;
  41.  
  42.             for (int i = 0; i < YCount; i++)
  43.             {
  44.                 if (i % YCount == 0)
  45.                 {
  46.                     RowIndex++;
  47.                     ColIndex = 0;
  48.                 }
  49.                 else
  50.                 {
  51.                     ColIndex++;
  52.                 }
  53.                 cells[GridIndex] = world.GetCell(basecell.XIndex, basecell.YIndex + ColIndex); // this is a 2D array [x,y]
  54.                 Console.WriteLine(GridIndex);
  55.                 GridIndex++;
  56.             }
  57.  
  58.  
  59.             return cells;
  60.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement