Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal static GridCell[] FindRequiredCells(GridWorld world, GridCell basecell, CellOccupant occupant)
- {
- GridCell[] cells = null;
- int XCount = (occupant.SizeX * world.CellSize) / world.CellSize;
- int YCount = (occupant.SizeY * world.CellSize) / world.CellSize;
- if (XCount == 1 && YCount == 1)
- {
- return new GridCell[1] { basecell };
- }
- var RequiredGridCount = XCount * YCount;
- cells = new GridCell[RequiredGridCount+1];
- int RowIndex = -1;
- int ColIndex = 0;
- int GridIndex = 0;
- for (int i = 0; i < XCount; i++)
- {
- if (i % XCount == 0)
- {
- RowIndex++;
- ColIndex = 0;
- }
- else
- {
- ColIndex++;
- }
- cells[GridIndex] = world.GetCell(basecell.XIndex + ColIndex, basecell.YIndex);
- GridIndex++;
- }
- RowIndex = -1;
- ColIndex = 0;
- for (int i = 0; i < YCount; i++)
- {
- if (i % YCount == 0)
- {
- RowIndex++;
- ColIndex = 0;
- }
- else
- {
- ColIndex++;
- }
- cells[GridIndex] = world.GetCell(basecell.XIndex, basecell.YIndex + ColIndex); // this is a 2D array [x,y]
- Console.WriteLine(GridIndex);
- GridIndex++;
- }
- return cells;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement