コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (Clock.Instance.State != Clock.ClockState.Game)
        {
            return;
        }

        if (block.State == Block.BlockState.Sliding)
        {
            Elapsed += Time.deltaTime;

            if (Elapsed >= Duration)
            {
                block.State = TargetState;
                block.Type  = TargetType;

                Direction = SlideDirection.None;

                if (block.State == Block.BlockState.Idle)
                {
                    matchDetector.RequestMatchDetection(block);
                }
            }
        }
    }
コード例 #2
0
    void Update()
    {
        for (int column = 0; column < columns.Value; column++)
        {
            bool emptyBlockDetected = false;

            // Traverse from bottom to top to detect whether there are any empty blocks underneath the current one
            for (int row = 0; row < rows.Value + 1; row++)
            {
                if (blockManager.Blocks[column, row].State == BlockState.Empty)
                {
                    emptyBlockDetected = true;
                }

                // If the current block is idle and there's atleast one empty one underneath it, make it fall
                if (blockManager.Blocks[column, row].State == BlockState.Idle && emptyBlockDetected)
                {
                    blockManager.Blocks[column, row].Faller.SetTarget(blockManager.Blocks[column, row - 1]);
                    blockManager.Blocks[column, row].Faller.Fall();
                }

                // If the current block just fell...
                if (blockManager.Blocks[column, row].Faller.JustFell)
                {
                    // If the block underneath (assuming there is one) is empty or currently falling
                    if (row > 0 && (blockManager.Blocks[column, row - 1].State == BlockState.Empty || blockManager.Blocks[column, row - 1].State == BlockState.Falling))
                    {
                        // Make them continue falling immediately
                        blockManager.Blocks[column, row].Faller.SetTarget(blockManager.Blocks[column, row - 1]);
                        blockManager.Blocks[column, row].Faller.ContinueFalling();
                    }
                    // Otherwise, land the block and request a match detection
                    else
                    {
                        blockManager.Blocks[column, row].State             = BlockState.Idle;
                        blockManager.Blocks[column, row].Faller.JustLanded = true;
                        matchDetector.RequestMatchDetection(blockManager.Blocks[column, row]);
                        audioCue.Play(audioSource);
                    }

                    blockManager.Blocks[column, row].Faller.JustFell = false;
                }
            }
        }
    }
コード例 #3
0
    void Update()
    {
        if (Block.State == BlockState.Sliding)
        {
            Elapsed += Time.deltaTime;

            if (Elapsed >= Duration)
            {
                Block.State = TargetState;
                Block.Type  = TargetType;
                Direction   = SlideDirection.None;

                if (Block.State == BlockState.Idle)
                {
                    matchDetector.RequestMatchDetection(Block);
                }
            }
        }
    }
コード例 #4
0
    void Update()
    {
        if (block.State == BlockState.Sliding)
        {
            Elapsed += Time.deltaTime;

            if (Elapsed >= slideDuration.Value)
            {
                block.State = targetState;
                block.Type  = targetType;
                Elapsed     = 0;
                Direction   = SlideDirection.None;

                if (matchDetector != null)
                {
                    matchDetector.RequestMatchDetection(block);
                }
            }
        }
    }
コード例 #5
0
    void Update()
    {
        // Traverse columns right-to-left so that when you encounter the leftmost garbage block, you can walk back right to see if the entire group can fall
        for (int column = BlockManager.Columns - 1; column >= 0; column--)
        {
            bool emptyBlockDetected = false;

            // Traverse from bottom to top to detect whether there are any empty blocks underneath the current one
            for (int row = 0; row < BlockManager.Rows; row++)
            {
                if (BlockManager.Blocks[column, row].State == BlockState.Empty)
                {
                    emptyBlockDetected = true;
                }

                // If the current block is idle and there's atleast one empty one underneath it...
                if (BlockManager.Blocks[column, row].State == BlockState.Idle && emptyBlockDetected)
                {
                    // For normal blocks, just make them fall immediately
                    if (BlockManager.Blocks[column, row].Type != 5)
                    {
                        BlockManager.Blocks[column, row].Faller.Target = BlockManager.Blocks[column, row - 1];
                        BlockManager.Blocks[column, row].Faller.Fall();
                    }

                    // For garbage blocks, mark them as being able to fall
                    else
                    {
                        BlockManager.Blocks[column, row].Garbage.CanFall = true;

                        // If this is the leftmost garbage block, go back through them to see if they can all fall
                        if (!BlockManager.Blocks[column, row].Garbage.IsNeighbor)
                        {
                            bool shouldFall = true;

                            for (int garbageColumn = column; garbageColumn < column + BlockManager.Blocks[column, row].Garbage.Width; garbageColumn++)
                            {
                                if (!BlockManager.Blocks[garbageColumn, row].Garbage.CanFall)
                                {
                                    shouldFall = false;
                                }
                            }

                            // If all of the garbage blocks in a group can fall, make them fall together
                            if (shouldFall)
                            {
                                for (int garbageColumn = column; garbageColumn < column + BlockManager.Blocks[column, row].Garbage.Width; garbageColumn++)
                                {
                                    for (int garbageRow = row; garbageRow < row + BlockManager.Blocks[column, row].Garbage.Height; garbageRow++)
                                    {
                                        BlockManager.Blocks[garbageColumn, garbageRow].Faller.Target = BlockManager.Blocks[garbageColumn, garbageRow - 1];
                                        BlockManager.Blocks[garbageColumn, garbageRow].Faller.Fall();
                                    }
                                }
                            }
                        }
                    }
                }

                // If the current block just fell...
                if (BlockManager.Blocks[column, row].Faller.JustFell)
                {
                    // If the block underneath (assuming there is one) is empty or currently falling
                    if (row > 0 && (BlockManager.Blocks[column, row - 1].State == BlockState.Empty || BlockManager.Blocks[column, row - 1].State == BlockState.Falling))
                    {
                        // For normal blocks, make them continue falling immediately
                        if (BlockManager.Blocks[column, row].Type != 5)
                        {
                            BlockManager.Blocks[column, row].Faller.Target = BlockManager.Blocks[column, row - 1];
                            BlockManager.Blocks[column, row].Faller.ContinueFalling();
                        }

                        // For garbage blocks, mark them as being able to continue falling
                        else
                        {
                            BlockManager.Blocks[column, row].Garbage.CanContinueFalling = true;

                            // Similar pattern as above. If this is the leftmost garbage block, go back through to see if they can all continue falling
                            if (!BlockManager.Blocks[column, row].Garbage.IsNeighbor)
                            {
                                bool shouldContinueFalling = true;

                                for (int garbageColumn = column; garbageColumn < column + BlockManager.Blocks[column, row].Garbage.Width; garbageColumn++)
                                {
                                    if (!BlockManager.Blocks[garbageColumn, row].Garbage.CanContinueFalling)
                                    {
                                        shouldContinueFalling = false;
                                    }
                                }

                                // If all of the garbage blocks in a group can continue falling, make them continue falling together
                                if (shouldContinueFalling)
                                {
                                    for (int garbageColumn = column; garbageColumn < column + BlockManager.Blocks[column, row].Garbage.Width; garbageColumn++)
                                    {
                                        for (int garbageRow = row; garbageRow < row + BlockManager.Blocks[column, row].Garbage.Height; garbageRow++)
                                        {
                                            BlockManager.Blocks[garbageColumn, garbageRow].Faller.Target = BlockManager.Blocks[garbageColumn, garbageRow - 1];
                                            BlockManager.Blocks[garbageColumn, garbageRow].Faller.ContinueFalling();
                                        }
                                    }
                                }

                                // Otherwise, make them all land together
                                else
                                {
                                    for (int garbageColumn = column; garbageColumn < column + BlockManager.Blocks[column, row].Garbage.Width; garbageColumn++)
                                    {
                                        for (int garbageRow = row; garbageRow < row + BlockManager.Blocks[column, row].Garbage.Height; garbageRow++)
                                        {
                                            BlockManager.Blocks[garbageColumn, garbageRow].State = BlockState.Idle;
                                            AudioSource.clip = LandClip; // Todo: Make this a garbage block landing clip
                                            AudioSource.Play();
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        BlockManager.Blocks[column, row].State = BlockState.Idle;
                        MatchDetector.RequestMatchDetection(BlockManager.Blocks[column, row]);
                        AudioSource.clip = LandClip;
                        AudioSource.Play();
                    }

                    BlockManager.Blocks[column, row].Faller.JustFell = false;
                }
            }
        }

        // In Time Attack mode, spawn in new blocks from the top when there's space to add them
        if (MinigameManager.Mode == BlockPartyModes.TimeAttack)
        {
            for (int column = 0; column < BlockManager.Columns; column++)
            {
                if (BlockManager.Blocks[column, BlockManager.Rows - 1].State == BlockState.Empty)
                {
                    BlockManager.Blocks[column, BlockManager.Rows - 1].Type = BlockManager.GetRandomBlockType(column, BlockManager.Rows - 1);

                    if (BlockManager.Blocks[column, BlockManager.Rows - 2].State == BlockState.Idle)
                    {
                        BlockManager.Blocks[column, BlockManager.Rows - 1].State = BlockState.Idle;
                    }

                    if (BlockManager.Blocks[column, BlockManager.Rows - 2].State == BlockState.Empty || BlockManager.Blocks[column, BlockManager.Rows - 2].State == BlockState.Falling)
                    {
                        BlockManager.Blocks[column, BlockManager.Rows - 1].Faller.Target = BlockManager.Blocks[column, BlockManager.Rows - 2];
                        BlockManager.Blocks[column, BlockManager.Rows - 1].Faller.ContinueFalling();
                    }
                }
            }
        }
    }
コード例 #6
0
    // Update is called once per frame
    void Update()
    {
        if (Clock.Instance.State != Clock.ClockState.Game)
        {
            return;
        }

        for (int x = 0; x < Board.Columns; x++)
        {
            bool emptyBlockDetected = false;

            for (int y = 0; y < Board.Rows; y++)
            {
                if (board.Blocks [x, y].State == Block.BlockState.Empty)
                {
                    emptyBlockDetected = true;
                }

                if (board.Blocks [x, y].State == Block.BlockState.Idle && emptyBlockDetected)
                {
                    board.Blocks [x, y].GetComponent <BlockFaller>().Target = board.Blocks [x, y - 1];
                    board.Blocks [x, y].GetComponent <BlockFaller>().Fall();
                }

                if (board.Blocks [x, y].GetComponent <BlockFaller>().JustFell)
                {
                    if (y > 0 && (board.Blocks [x, y - 1].State == Block.BlockState.Empty || board.Blocks [x, y - 1].State == Block.BlockState.Falling))
                    {
                        board.Blocks [x, y].GetComponent <BlockFaller>().Target = board.Blocks [x, y - 1];
                        board.Blocks [x, y].GetComponent <BlockFaller>().ContinueFalling();
                    }
                    else
                    {
                        board.Blocks [x, y].State = Block.BlockState.Idle;

                        matchDetector.RequestMatchDetection(board.Blocks [x, y]);
                    }

                    board.Blocks [x, y].GetComponent <BlockFaller>().JustFell = false;
                }
            }
        }

        // Add new blocks on the top of the board
        for (int x = 0; x < Board.Columns; x++)
        {
            if (board.Blocks[x, Board.Rows - 1].State == Block.BlockState.Empty)
            {
                int type;

                do
                {
                    type = Random.Range(0, Block.TypeCount);
                } while((x != 0 && board.Blocks[x - 1, Board.Rows - 1].Type == type) || board.Blocks[x, Board.Rows - 1].Type == type);

                board.Blocks[x, Board.Rows - 1].Type = type;

                if (board.Blocks[x, Board.Rows - 2].State == Block.BlockState.Idle)
                {
                    board.Blocks[x, Board.Rows - 1].State = Block.BlockState.Idle;
                }

                if (board.Blocks[x, Board.Rows - 2].State == Block.BlockState.Empty || board.Blocks[x, Board.Rows - 2].State == Block.BlockState.Falling)
                {
                    board.Blocks[x, Board.Rows - 1].GetComponent <BlockFaller>().Target = board.Blocks[x, Board.Rows - 2];
                    board.Blocks[x, Board.Rows - 1].GetComponent <BlockFaller>().ContinueFalling();
                }
            }
        }
    }
コード例 #7
0
    void FixedUpdate()
    {
        if (Game.State == GameState.InMinigame && Game.Mode == GameMode.Survival)
        {
            if (isForcingRaise)
            {
                raiseRate = ManualRaiseRate.Value;
            }
            else
            {
                // Scale raise rate based on remaining time
                raiseRate = Mathf.Lerp(MinimumRaiseRate.Value, MaximumRaiseRate.Value, ((GameConfiguration.InMinigameDuration / 1000) - Game.SecondsRemaining) / (GameConfiguration.InMinigameDuration / 1000));
            }

            for (int column = 0; column < BlockManager.Columns; column++)
            {
                for (int row = 0; row < BlockManager.Rows; row++)
                {
                    if (BlockManager.Blocks[column, row].State != BlockState.Empty &&
                        BlockManager.Blocks[column, row].State != BlockState.Idle &&
                        BlockManager.Blocks[column, row].State != BlockState.Sliding)
                    {
                        raiseRate = 0;
                    }

                    if (row == BlockManager.Rows - 2)
                    {
                        if (BlockManager.Blocks[column, row].State != BlockState.Empty)
                        {
                            isLossIncoming = true;
                        }
                    }
                }
            }

            if (isLossIncoming)
            {
                LossElapsed += raiseRate * Time.deltaTime;

                if (LossElapsed >= RaiseLossCountdownDuration.Value)
                {
                    OnPlayerEliminated.Raise();
                }
            }
            else
            {
                Elapsed += raiseRate * Time.deltaTime;

                if (Elapsed >= RaiseDuration.Value)
                {
                    Elapsed = 0f;

                    for (int column = 0; column < BlockManager.Columns; column++)
                    {
                        for (int row = BlockManager.Rows - 2; row >= 1; row--)
                        {
                            BlockManager.Blocks[column, row].Garbage.Width      = BlockManager.Blocks[column, row - 1].Garbage.Width;
                            BlockManager.Blocks[column, row].Garbage.Height     = BlockManager.Blocks[column, row - 1].Garbage.Height;
                            BlockManager.Blocks[column, row].Garbage.IsNeighbor = BlockManager.Blocks[column, row - 1].Garbage.IsNeighbor;
                            BlockManager.Blocks[column, row].State = BlockManager.Blocks[column, row - 1].State;
                            BlockManager.Blocks[column, row].Type  = BlockManager.Blocks[column, row - 1].Type;
                        }

                        BlockManager.Blocks[column, 0].State = BlockManager.NewRowBlocks[column].State;
                        BlockManager.Blocks[column, 0].Type  = BlockManager.NewRowBlocks[column].Type;

                        MatchDetector.RequestMatchDetection(BlockManager.Blocks[column, 0]);
                    }

                    BlockManager.CreateNewRowBlocks();

                    if (isForcingRaise)
                    {
                        Score.ScoreRaise();

                        isForcingRaise = false;
                    }

                    if (Controller.Row < BlockManager.Rows - 2)
                    {
                        Controller.Row++;
                    }
                }

                LossElapsed = 0;
            }

            isLossIncoming = false;
        }
    }
コード例 #8
0
    void Update()
    {
        if (MinigameManager.Mode == BlockPartyModes.Survival)
        {
            float raiseRate;
            if (isForcingRaise)
            {
                raiseRate = forcedRaiseRate;
            }
            else
            {
                raiseRate = defaultRaiseRate;
            }

            for (int column = 0; column < BlockManager.Columns; column++)
            {
                for (int row = 0; row < BlockManager.Rows; row++)
                {
                    if (BlockManager.Blocks[column, row].State != BlockState.Empty &&
                        BlockManager.Blocks[column, row].State != BlockState.Idle &&
                        BlockManager.Blocks[column, row].State != BlockState.Sliding)
                    {
                        raiseRate = 0;
                    }

                    if (row == BlockManager.Rows - 2)
                    {
                        if (BlockManager.Blocks[column, row].State != BlockState.Empty)
                        {
                            isLossIncoming = true;
                        }
                    }
                }
            }

            if (isLossIncoming)
            {
                LossElapsed += raiseRate * Time.deltaTime;

                if (LossElapsed >= LossDuration)
                {
                    MinigameManager.EndGame();
                }
            }
            else
            {
                Elapsed += raiseRate * Time.deltaTime;

                if (Elapsed >= Duration)
                {
                    Elapsed = 0f;

                    for (int column = 0; column < BlockManager.Columns; column++)
                    {
                        for (int row = BlockManager.Rows - 2; row >= 1; row--)
                        {
                            BlockManager.Blocks[column, row].Garbage.Width      = BlockManager.Blocks[column, row - 1].Garbage.Width;
                            BlockManager.Blocks[column, row].Garbage.Height     = BlockManager.Blocks[column, row - 1].Garbage.Height;
                            BlockManager.Blocks[column, row].Garbage.IsNeighbor = BlockManager.Blocks[column, row - 1].Garbage.IsNeighbor;
                            BlockManager.Blocks[column, row].State = BlockManager.Blocks[column, row - 1].State;
                            BlockManager.Blocks[column, row].Type  = BlockManager.Blocks[column, row - 1].Type;
                        }

                        BlockManager.Blocks[column, 0].State = BlockManager.NewRowBlocks[column].State;
                        BlockManager.Blocks[column, 0].Type  = BlockManager.NewRowBlocks[column].Type;

                        MatchDetector.RequestMatchDetection(BlockManager.Blocks[column, 0]);
                    }

                    BlockManager.CreateNewRowBlocks();

                    if (isForcingRaise)
                    {
                        Score.ScoreRaise();

                        isForcingRaise = false;
                    }
                }

                LossElapsed = 0;
            }

            isLossIncoming = false;
        }
    }
コード例 #9
0
    // Update is called once per frame
    void Update()
    {
        //if(Clock.Instance.State != Clock.ClockState.Game) {
        //    return;
        //}

        for (int x = 0; x < Board.Columns; x++)
        {
            bool emptyBlockDetected = false;

            for (int y = 0; y < Board.Rows; y++)
            {
                if (board.Blocks [x, y].State == BlockState.Empty)
                {
                    emptyBlockDetected = true;
                }

                if (board.Blocks [x, y].State == BlockState.Idle && emptyBlockDetected)
                {
                    board.Blocks [x, y].GetComponent <BlockFaller>().Target = board.Blocks [x, y - 1];
                    board.Blocks [x, y].GetComponent <BlockFaller>().Fall();
                }

                if (board.Blocks [x, y].GetComponent <BlockFaller>().JustFell)
                {
                    if (y > 0 && (board.Blocks [x, y - 1].State == BlockState.Empty || board.Blocks [x, y - 1].State == BlockState.Falling))
                    {
                        board.Blocks [x, y].GetComponent <BlockFaller>().Target = board.Blocks [x, y - 1];
                        board.Blocks [x, y].GetComponent <BlockFaller>().ContinueFalling();
                    }
                    else
                    {
                        board.Blocks [x, y].State = BlockState.Idle;

                        matchDetector.RequestMatchDetection(board.Blocks [x, y]);
                    }

                    board.Blocks [x, y].GetComponent <BlockFaller>().JustFell = false;
                }
            }
        }

        // Add new blocks on the top of the board
        for (int x = 0; x < Board.Columns; x++)
        {
            if (board.Blocks[x, Board.Rows - 1].State == BlockState.Empty)
            {
                board.Blocks[x, Board.Rows - 1].Type = board.GetRandomBlockType(x, Board.Rows - 1);

                if (board.Blocks[x, Board.Rows - 2].State == BlockState.Idle)
                {
                    board.Blocks[x, Board.Rows - 1].State = BlockState.Idle;
                }

                if (board.Blocks[x, Board.Rows - 2].State == BlockState.Empty || board.Blocks[x, Board.Rows - 2].State == BlockState.Falling)
                {
                    board.Blocks[x, Board.Rows - 1].GetComponent <BlockFaller>().Target = board.Blocks[x, Board.Rows - 2];
                    board.Blocks[x, Board.Rows - 1].GetComponent <BlockFaller>().ContinueFalling();
                }
            }
        }
    }