public static FlyingBlock Constract(Matrix4x4Bool blockStruct, Material opaqueMat, Material transparentMat, Grid grid) { if (block == null) { block = Resources.Load <GameObject>("Prefabs/Block"); } var newBlock = new GameObject("FlyingBlock").AddComponent <FlyingBlock>(); newBlock.FadeMaterial = transparentMat; newBlock.Blocks = new GameObject[blockStruct.GetSum()]; newBlock.blockStruct = blockStruct; newBlock.grid = grid; int index = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (blockStruct[i, j]) { var blockInst = Instantiate(block, newBlock.transform); blockInst.transform.localPosition = new Vector3(i, -j); blockInst.GetComponent <MeshRenderer>().sharedMaterial = opaqueMat; newBlock.Blocks[index] = blockInst; index++; } } } return(newBlock); }
public void UpdateGrid(Vector2Int position, GameObject[] objects, Matrix4x4Bool blockStruct, Material fadeMat, out bool isOutOfBoundsTop) { if (position.y >= size.y) { isOutOfBoundsTop = true; return; } isOutOfBoundsTop = false; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (blockStruct[i, j]) { var actualPos = position + new Vector2Int(i, -j); if (actualPos.x >= 0 && actualPos.x < size.x && actualPos.y >= 0 && actualPos.y < size.y) { grid[actualPos.x, actualPos.y] = true; } } } } foreach (var o in objects) { var objectPos = transform.InverseTransformPoint(o.transform.position); o.transform.SetParent(transform); realBlocks[Mathf.FloorToInt(objectPos.x), Mathf.FloorToInt(objectPos.y)] = o; fadeMaterials[Mathf.FloorToInt(objectPos.x), Mathf.FloorToInt(objectPos.y)] = fadeMat; } }
private void InputManagerOnRotate() { var preRotateState = blockStruct; blockStruct.Rotate(); blockStruct.MirrorWithShift(); if (grid.CheckCollision(Position, BlockStruct, out var byBounds)) { blockStruct = preRotateState; } else { SetupBricks(); } }
public bool CheckCollision(Vector2Int position, Matrix4x4Bool blockStruct, out bool byBoundsHorizontal) { var bounds = blockStruct.GetBounds(); byBoundsHorizontal = true; if (position.x < 0 || position.x + bounds.x > size.x) { return(true); } byBoundsHorizontal = false; if (position.y - bounds.y + 1 < 0) { return(true); } for (int i = 0; i < bounds.x; i++) { var currentColumnSize = blockStruct.GetRow(i).Max; for (int j = 0; j < currentColumnSize; j++) { if (position.y - j >= size.y) { continue; } if (grid[position.x + i, position.y - j] && blockStruct[i, j]) { return(true); } } } return(false); }