Beispiel #1
0
    private void CreateNewBlock()
    {
        var materials = colorsDatabase.GetRandom();

        if (nextBlock == null)
        {
            nextBlock = FlyingBlock.Constract(blocksDatabase.GetRandom(), materials.Item1, materials.Item2, grid);
        }

        currentBlock = nextBlock;
        currentBlock.gameObject.SetActive(true);
        currentBlock.transform.SetParent(grid.transform);
        currentBlock.transform.localPosition = new Vector3(4, 22);

        materials = colorsDatabase.GetRandom();
        nextBlock = FlyingBlock.Constract(blocksDatabase.GetRandom(), materials.Item1, materials.Item2, grid);
        blockRenderer.CaptureBlock(nextBlock);
        nextBlock.gameObject.SetActive(false);
    }
Beispiel #2
0
    private void ExecuteStep()
    {
        if (currentBlock != null)
        {
            currentBlock.transform.localPosition -= new Vector3(0, 1, 0);
        }

        if (currentBlock == null)
        {
            CreateNewBlock();
        }

        if (grid.CheckCollision(currentBlock.Position, currentBlock.BlockStruct, out var byBoundsHorizontal))
        {
            if (!byBoundsHorizontal)
            {
                currentBlock.transform.localPosition += new Vector3(0, 1, 0);
            }

            grid.UpdateGrid(currentBlock.Position, currentBlock.Blocks, currentBlock.BlockStruct, currentBlock.FadeMaterial, out var isOutOfBoundsTop);
            if (isOutOfBoundsTop)
            {
                EndGame();
                return;
            }

            Destroy(currentBlock.gameObject);
            currentBlock = null;

            var lines = grid.CheckLines();
            if (lines != null)
            {
                progressionController.AddScore(lines.Length);
                CalculateSpeedUp();
                StartCoroutine(RemoveLinesFromGrid(lines));
            }
        }
    }