private void UpdatePieceStateAndEffectState(ref PieceState pieceState, int col, int index, int combo)
            {
                if (pieceState.isBanish)
                {
                    return;
                }

                pieceState.isBanish = true;
                pieceState.color    = col;
                pieceState.combo    = combo;
                pieceStates[index]  = pieceState;
                UpdateEffectState(piecePositions[index].gridPosition);
            }
            private void UpdatePieceState()
            {
                for (int i = 0; i < gridStates.Length; i++)
                {
                    GridState  gridState  = gridStates[i];
                    PieceState pieceState = pieceStates[gridState.pieceId];

                    if (pieceState.isBanish)
                    {
                        int x             = i % GridRowLength;
                        var piecePosition = piecePositions[gridState.pieceId];
                        piecePosition.fallLength          = fallCount[x] * GridSize;
                        piecePosition.fallCount           = 0;
                        piecePositions[gridState.pieceId] = piecePosition;
                    }

                    pieceState.isBanish            = false;
                    pieceStates[gridState.pieceId] = pieceState;
                }
            }
            private void UpdateReplacePosition()
            {
                for (int i = 0; i < gridStates.Length; i++)
                {
                    GridState     gridState     = gridStates[i];
                    PieceState    pieceState    = pieceStates[gridState.pieceId];
                    PiecePosition piecePosition = piecePositions[gridState.pieceId];
                    int           x             = i % GridRowLength;

                    if (pieceState.isBanish)
                    {
                        int posY = FieldHeight + (fallCount[x] * GridSize);
                        piecePosition.position = new Vector2Int(piecePosition.position.x, posY);
                        fallCount[x]          += 1;
                    }
                    else
                    {
                        piecePosition.fallLength = fallCount[x] * GridSize;
                        piecePosition.fallCount  = 0;
                    }
                    piecePositions[gridState.pieceId] = piecePosition;
                }
            }
示例#4
0
 Mesh GetMeshe(PieceState state)
 {
     return(Shared.puzzleMeshMat.meshes[$"piece_0{state.color}"]);
 }
            private void CheckLine(ref FieldBanish fieldBanish)
            {
                var fieldInput = fieldInputs[0];

                if (!fieldInput.isOnGrid)
                {
                    return;
                }

                int nextCombo = fieldBanish.combo + 1;

                for (int x = 0; x < GridRowLength; x++)
                {
                    for (int y = 0; y < GridColumnLength; y++)
                    {
                        checkStates[y] = pieceStates[gridStates[x + GridRowLength * y].pieceId];
                    }
                    bool isSameColor = CheckLine(checkStates, GridColumnLength, nextCombo);

                    if (isSameColor)
                    {
                        UpdateFieldBanish(ref fieldBanish, x, 0, nextCombo);
                        int col = 0;
                        for (int y = 0; y < GridColumnLength; y++)
                        {
                            int        index      = gridStates[x + GridRowLength * y].pieceId;
                            PieceState pieceState = pieceStates[index];
                            UpdatePieceStateAndEffectState(ref pieceState, col, index, nextCombo);
                            col++;
                        }
                    }
                }

                for (int y = 0; y < GridColumnLength; y++)
                {
                    for (int x = 0; x < GridRowLength; x++)
                    {
                        checkStates[x] = pieceStates[gridStates[x + GridRowLength * y].pieceId];
                    }
                    bool isSameColor = CheckLine(checkStates, GridRowLength, nextCombo);

                    if (isSameColor)
                    {
                        int col = 0;
                        UpdateFieldBanish(ref fieldBanish, 0, y, nextCombo);
                        for (int x = 0; x < GridRowLength; x++)
                        {
                            int        index      = gridStates[x + GridRowLength * y].pieceId;
                            PieceState pieceState = pieceStates[index];
                            UpdatePieceStateAndEffectState(ref pieceState, col, index, nextCombo);
                            col++;
                        }
                    }
                }

                if (fieldBanish.phase == EnumBanishPhase.BanishEnd)
                {
                    fieldBanish.phase = EnumBanishPhase.FallStart;
                    fieldBanish.combo = 0;
                    fieldBanishs[0]   = fieldBanish;
                }
            }