Esempio n. 1
0
    int PopEggsFlashEgg(Egg egg)
    {
        int r            = egg.GetRow();
        int crackedCount = 0;

        for (int c = 0; c < COLUMNS; c++)
        {
            if (mGird[r][c].gameObject.activeSelf)
            {
                //Debug.Log("UHM: "+r+":"+c);
                if (mGird[r][c].IsHazard())
                {
                    mGird[r][c].SetHazard(false);
                    currentHazardCount--;
                }
                mEggAnimation.GetComponent <EggAnimationHandler>().AddBrokenEgg(mGird[r][c]);
                mGird[r][c].SetColor((int)Defines.COLOR.NONE);
                mGird[r][c].gameObject.SetActive(false);
                crackedCount++;
            }
        }
        forceSpawnLine = true;
        for (int c = 0; c < COLUMNS; c++)
        {
            if (mGird[0][c].GetColor() != (int)Defines.COLOR.NONE && mGird[0][c].gameObject.activeSelf)
            {
                forceSpawnLine = false;
                break;
            }
        }
        return(crackedCount);
    }
Esempio n. 2
0
    // Find closest egg, which takes bullet egg and eggOnGrid to process;
    Egg GetNewEggPosition(GameObject eggOnGrid, GameObject refBullet)
    {
        Vector3 direction     = refBullet.transform.position - eggOnGrid.transform.position;     // this is a vector from hit egg to bullet
        Egg     eggData       = eggOnGrid.GetComponent <Egg>();
        float   AngleOfVector = Vector3.Angle(Vector3.up, direction);

        if (direction.x < 0)
        {
            AngleOfVector = -AngleOfVector;
        }
        int offsetRow = (eggData.GetRow() % 2 == 1) ? 0 : 1;
        int newCol    = -1;
        int newRow    = -1;
        //Debug.Log(AngleOfVector);
        int positionKey = GetPositionFromKey(eggData, GetKeyFromAngle(AngleOfVector), out newRow, out newCol);
        //Debug.Log(eggData.GetRow() +":"+ eggData.GetCol()+ " ;; New egg: "+newRow+":"+newCol);
        Egg firstCandidate = GetEggInGrid(newRow, newCol);

        //Debug.Log(firstCandidate.GetStringFromColor());
        if (firstCandidate.GetStringFromColor() != "None") // We have to fetch second candidate, as this one is there
        {
            //Debug.Log("Failed 1");
            int   newKey       = -1;
            float minAngleDiff = 181f;
            for (int key = 1; key <= 6; key++)
            {
                if (key != positionKey)
                {
                    //Debug.Log("Key "+key+" : "+Mathf.Abs(GetAngleCenterByKey(key) - AngleOfVector));
                    if (Mathf.Abs(GetAngleCenterByKey(key) - AngleOfVector) < minAngleDiff)
                    {
                        newKey       = key;
                        minAngleDiff = Mathf.Abs(GetAngleCenterByKey(key) - AngleOfVector);
                    }
                }
            }
            GetPositionFromKey(eggData, newKey, out newRow, out newCol);
            //Debug.Log("C2: "+eggData.GetRow() +":"+ eggData.GetCol()+ " ;; New egg: "+newRow+":"+newCol);
            return(GetEggInGrid(newRow, newCol));
        }
        return(firstCandidate);
    }
Esempio n. 3
0
    int GetPositionFromKey(Egg eggData, int key, out int newRow, out int newCol)
    {
        int offsetRow = (eggData.GetRow() % 2 == (isOdd() ? 1 : 0)) ? 1 : 0;

        newCol = -1;
        newRow = -1;
        //Debug.Log(key + " and " + offsetRow);
        switch (key)
        {
        case 1:
            newCol = eggData.GetCol() + offsetRow;
            newRow = eggData.GetRow() - 1;
            break;

        case 2:
            newCol = eggData.GetCol() + 1;
            newRow = eggData.GetRow();
            break;

        case 3:
            newCol = eggData.GetCol() + offsetRow;
            newRow = eggData.GetRow() + 1;
            break;

        case 4:
            newCol = eggData.GetCol() - 1 + offsetRow;
            newRow = eggData.GetRow() + 1;
            break;

        case 5:
            newCol = eggData.GetCol() - 1;
            newRow = eggData.GetRow();
            break;

        case 6:
            newCol = eggData.GetCol() - 1 + offsetRow;
            newRow = eggData.GetRow() - 1;
            break;
        }
        return(key);
    }