Created
August 10, 2025 10:36
-
-
Save ShuraProgerMain/8be5065ddbdc1ac6b5ea62ecd3bca17b to your computer and use it in GitHub Desktop.
Code for block placement in grid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public readonly struct CellPosGrade | |
{ | |
public readonly int X; | |
public readonly int Y; | |
public readonly int Grade; | |
public CellPosGrade(int x, int y, int grade) | |
{ | |
X = x; | |
Y = y; | |
Grade = grade; | |
} | |
} | |
public record BlockData | |
{ | |
public Vector2Int Size; | |
public Vector2Int Center; | |
public readonly List<BlockCell> ActiveCells = new(); | |
public readonly List<Sprite> CellsImages = new(); | |
public void Clear() | |
{ | |
ActiveCells.Clear(); | |
CellsImages.Clear(); | |
} | |
} | |
private readonly List<CellPosGrade> _fakeFillCellsNew = new(); | |
private BlockData[] _blocksData; | |
private CalculationResult CalculateBlockPlacement(Vector2Int currentPosition, int blockIndex) | |
{ | |
Vector2Int startPosition = currentPosition; | |
var cells = new CellPosGrade[_blocksData[blockIndex].ActiveCells.Count]; | |
int count = 0; | |
foreach (BlockCell blockCell in _blocksData[blockIndex].ActiveCells) | |
{ | |
int nextX = startPosition.y + blockCell.X; | |
int nextY = startPosition.x + blockCell.Y; | |
if (nextX < 0 || nextY < 0 || nextX >= FieldSize.x || nextY >= FieldSize.y || _cells[nextY, nextX] > 0) | |
{ | |
cells = new CellPosGrade[_blocksData[blockIndex].ActiveCells.Count]; | |
break; | |
} | |
cells[count] = new CellPosGrade(nextY, nextX, blockCell.Grade); | |
count++; | |
} | |
return new CalculationResult( startPosition, cells); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment