Esempio n. 1
0
    void InitPlayField()
    {
        mOdd = false;
        for (int r = 0; r < ROWS; r++)
        {
            List <Egg> eggs   = new List <Egg>();
            float      offset = (mOdd) ? OFFSET_EGG : 0;

            for (int c = 0; c < COLUMNS; c++)
            {
                GameObject obj = Instantiate(mEggPrefab, transform.position, Quaternion.identity);
                obj.transform.parent = gameObject.transform;
                Egg egg = obj.GetComponent <Egg>();
                egg.SetPosition(c, r, offset);
                int color = Random.Range(0, Defines.EggCount);
                egg.SetColor(color);
                egg.gameObject.SetActive(false);
                egg.SetHazard(false);
                eggs.Add(egg);
            }
            mGird.Add(eggs);
            mOdd = !mOdd;
        }
        mOdd = true;
        for (int i = 0; i < NUM_ROWS_SHOW; ++i)
        {
            SpawnLine();
        }
        SetState(STATE.PLAYGAME);
    }
Esempio n. 2
0
    void SpawnLine()
    {
        for (int r = ROWS - 2; r >= 0; r--)
        {
            foreach (Egg e in mGird[r])
            {
                mGird[r + 1][e.GetCol()].SetColor(e.GetColor());
                mGird[r + 1][e.GetCol()].SetHazard(e.IsHazard());
                mGird[r + 1][e.GetCol()].SetPosition(e.GetCol(), r + 1, e.GetOffset());
                mGird[r + 1][e.GetCol()].gameObject.SetActive(e.gameObject.activeSelf);
                mGird[r + 1][e.GetCol()].UpdatePositionAnim(-Egg.EGG_RATIO, e.GetOffset());
            }
        }

        float offset = mOdd ? OFFSET_EGG : 0;

        for (int i = 0; i < COLUMNS; ++i)
        {
            Egg e = mGird[0][i];
            int color;

            int  left         = i == 0 ? 0 : mOdd ? i : i - 1;
            int  right        = i == (COLUMNS - 1) ? (COLUMNS - 1) : mOdd ? i + 1 : i;
            bool haveLeftEgg  = mGird[1][left].isActiveAndEnabled;
            bool haveRightEgg = mGird[1][right].isActiveAndEnabled;

            if (Random.Range(0, 100) < WEIGHTED_RANDOM_CHANCE && (haveLeftEgg || haveRightEgg))            // 80%
            {
                if (haveLeftEgg && haveRightEgg)
                {
                    if (Random.Range(0, 2) == 1)                     // 50%
                    {
                        color = mGird[1][left].GetColor();
                    }
                    else
                    {
                        color = mGird[1][right].GetColor();
                    }
                }
                else if (haveLeftEgg)
                {
                    color = mGird[1][left].GetColor();
                }
                else
                {
                    color = mGird[1][right].GetColor();
                }
            }
            else
            {
                color = Random.Range(0, Defines.EggCount);
            }
            e.SetColor(color);
            e.SetPosition(e.GetCol(), 0, offset);
            e.gameObject.SetActive(true);
            e.UpdatePositionAnim(-Egg.EGG_RATIO, e.GetOffset());
            e.SetHazard(false);
            if (Random.Range(0, 100) < HAZARD_CHANCE && currentHazardCount < MAX_HAZARD_ON_SCREEN)
            {
                switch (color)
                {
                case 2:
                case 4:
                    e.SetHazard(true);
                    currentHazardCount++;
                    break;
                }
            }
        }
        mOdd            = !mOdd;
        animateEggDown  = true;
        eggDownAnimTime = 0.0f;
    }