예제 #1
0
    public void ClearMatchesFromBoard()
    {
        bool removedAtLeastOne = false;

        for (int x = 0; x < gridModel.w; ++x)
        {
            for (int y = gridModel.h - 1; y >= 0; --y)
            {
                if (gridModel.grid[x, y] == null)
                {
                    continue;
                }
                MatchBlock mb = gridModel.grid[x, y].GetComponent <MatchBlock>();
                if (mb.IsMatched)
                {
                    Vector2 v = mb.GridPosition;
                    mb.PlaySettleEffect(settleEffect, true);
                    gridModel.deleteCell((int)v.x, (int)v.y);
                    removedAtLeastOne = true;
                }
            }
        }

        if (removedAtLeastOne)
        {
            SFXSelector.Instance.PlayRandomSound(destructionSounds);
        }
        // Send the matches to the rules object
        TetrisController.Rules.matchesMade.AddRange(matches);
    }
예제 #2
0
    public IEnumerator PopulateGrid()
    {
        WaitForEndOfFrame wait = new WaitForEndOfFrame();
        int count        = 0;
        int soundCounter = 0;

        for (int y = 0; y < gridModel.h; ++y)
        {
            for (int x = 0; x < gridModel.w; ++x)
            {
                Vector3    pos  = new Vector3(x + gridModel.offset.x, y + gridModel.offset.y, 0);
                GameObject go   = Instantiate <GameObject>(block, pos, Quaternion.identity, cachedTransform);
                int        type = Random.Range(0, blockMaterials.Count);
                MatchBlock mb   = go.GetComponent <MatchBlock>();
                if (mb)
                {
                    mb.gridModel = gridModel;
                    mb.SetBockType(type, blockMaterials[type]);
                    mb.IsMatched = false;
                    mb.settled   = true;
                }
                soundCounter++;
                if (soundCounter > 20)
                {
                    SFXSelector.Instance.PlayNextSound(spawnSounds);
                    soundCounter = 0;
                }
                count++;
                if (count >= spawnCount)
                {
                    count = 0;
                    yield return(wait);
                }
            }
        }
        ready = true;
        TetrisController.Rules.ready = true;
        // Play dust!
        for (int y = 0; y < gridModel.h; ++y)
        {
            for (int x = 0; x < gridModel.w; ++x)
            {
                if (gridModel.grid[x, y] != null)
                {
                    MatchBlock mb = gridModel.grid[x, y].GetComponent <MatchBlock>();
                    mb.PlaySettleEffect(settleEffect);
                }
            }
        }
        SFXSelector.Instance.PlayRandomSound(impactSounds, 1f);
        lastFallTime = lastMatchTime = Time.time;
    }