コード例 #1
0
    void ExpandFallenEggPool(Egg refEgg)
    {
        GameObject newEgg = Instantiate(mEggPrefab);

        newEgg.transform.parent   = gameObject.transform;
        newEgg.transform.position = refEgg.gameObject.transform.position;
        newEgg.gameObject.GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic;
        newEgg.gameObject.SetActive(true);
        newEgg.GetComponent <Egg>().SetColor(refEgg.GetColor());
        newEgg.gameObject.name = "FallenEgg";
        newEgg.gameObject.tag  = "Untagged";
        fallenEggPool.Add(newEgg);
    }
コード例 #2
0
 void SetFallenEggInPool(Egg refEgg, int position)
 {
     if (position >= fallenEggPool.Count)
     {
         ExpandFallenEggPool(refEgg);
     }
     else
     {
         fallenEggPool[position].transform.position = refEgg.gameObject.transform.position;
         fallenEggPool[position].GetComponent <Egg>().SetColor(refEgg.GetColor());
         fallenEggPool[position].gameObject.SetActive(true);
     }
 }
コード例 #3
0
    // Handle egg pop and fall, once hit grid, we are finding all nearby eggs with same color, and trigger pop and fall if >= 3 are the same
    public List <Egg> SpreadToAllNearbyEgg(Egg egg, bool isOnlyCheckSame = true)
    {
        Stack <Egg>     uncheckedEgg = new Stack <Egg>();     // contains all potential eggs that has not been further check
        SortedSet <Egg> checkedEgg   = new SortedSet <Egg>(); // contains all eggs that are checked
        List <Egg>      crackedEgg   = new List <Egg>();      // list of eggs that can be cracked (same color with hit)

        uncheckedEgg.Push(egg);
        crackedEgg.Add(egg);
        while (uncheckedEgg.Count > 0)
        {
            Egg currentEgg = uncheckedEgg.Pop();
            int curRow, curCol;
            for (int i = 1; i <= 6; i++)            // Check 6 eggs next to it
            {
                GetPositionFromKey(currentEgg, i, out curRow, out curCol);
                if (curRow < 0 || curRow > ROWS || curCol < 0 || curCol > COLUMNS)
                {
                    continue;
                }
                Egg eggKey = GetEggInGrid(curRow, curCol);
                if (eggKey != null)
                {
                    if (!checkedEgg.Contains(eggKey))
                    {
                        if (eggKey.GetStringFromColor() != "None")
                        {
                            if (isOnlyCheckSame && eggKey.GetColor() != currentEgg.GetColor())
                            {
                                continue;
                            }
                            if (!uncheckedEgg.Contains(eggKey))
                            {
                                uncheckedEgg.Push(eggKey);
                            }
                            if (!crackedEgg.Contains(eggKey))
                            {
                                crackedEgg.Add(eggKey);
                            }
                        }
                    }
                }
            }
            checkedEgg.Add(currentEgg);
        }
        return(crackedEgg);
    }
    public void AddBrokenEgg(Egg refEgg)
    {
        GameObject newEgg = Instantiate(eggPrefab);

        newEgg.transform.parent   = gameObject.transform;
        newEgg.transform.position = refEgg.gameObject.transform.position;
        newEgg.gameObject.SetActive(true);
        newEgg.GetComponent <Egg>().SetColor(refEgg.GetColor());
        newEgg.gameObject.name = "FallenEgg";
        newEgg.gameObject.tag  = "Untagged";
        Animator eggAnim = newEgg.GetComponent <Egg>().GetActiveChildEgg().GetComponent <Animator>();

        eggAnim.SetTrigger("TriggerStart");
        eggAnim.SetInteger("Color", newEgg.GetComponent <Egg>().GetColor());
        gameObjectList.Add(newEgg);
        gameObjectTimers.Add(0);
    }
コード例 #5
0
    void ActivateHazard(Egg egg)
    {
        if (GetHazardState() != HAZARD_STATUS.NONE)
        {
            return;
        }
        switch (egg.GetColor())
        {
        case (int)Defines.COLOR.LIGHT_BLUE:     // Frozen
            frozenHazardTime = 0.0f;
            frozenHazardObject.SetActive(true);
            SetHazardState(HAZARD_STATUS.FROZEN);
            AudioManager.Instance().PlaySFXFrozenHazard();
            break;

        case (int)Defines.COLOR.RED:     // Fire
            firewallHazardTime = 0.0f;
            firewallHazardObject.SetActive(true);
            SetHazardState(HAZARD_STATUS.FIREWALL);
            break;
        }
    }
コード例 #6
0
    // Handle adding egg to grid when hit, if eggOnGrid is null, it is hit at the top
    public void AttachEggOnGrid(GameObject eggOnGrid, GameObject refBullet)
    {
        float minDist = 99999.0f;
        Egg   newEgg  = null;

        if (eggOnGrid == null) // Hit on top case
        {
            for (int i = 0; i < GetMaxCol(); i++)
            {
                Egg   egg         = GetEggInGrid(0, i);
                float currentDist = Vector3.Distance(egg.gameObject.transform.position, refBullet.transform.position);
                if (currentDist < minDist)
                {
                    minDist = currentDist;
                    newEgg  = egg;
                }
            }
        }
        else // normal case
        {
            newEgg = GetNewEggPosition(eggOnGrid, refBullet);
        }
        int fallenCount  = 0;
        int crackedCount = 0;

        switch (refBullet.GetComponent <Bullet>().GetColor())
        {
        case (int)Defines.COLOR.SPECIAL_FLASH:

            if (eggOnGrid != null)
            {
                crackedCount = PopEggsFlashEgg(eggOnGrid.GetComponent <Egg>());
                mEggAnimation.GetComponent <EggAnimationHandler>().AddFlashBlast(eggOnGrid.transform.position);
            }
            else
            {
                crackedCount = PopEggsFlashEgg(newEgg);
                mEggAnimation.GetComponent <EggAnimationHandler>().AddFlashBlast(newEgg.transform.position);
            }
            fallenCount = FallEggs();
            //Debug.Log(crackedCount + " and " + fallenCount);
            AddTotalScoreByCount(crackedCount, fallenCount);
            AudioManager.Instance().PlaySFXFlashEgg();
            break;

        case (int)Defines.COLOR.SPECIAL_DARKGREY:
            if (eggOnGrid != null)
            {
                crackedCount = PopEggsPowerEgg(eggOnGrid.GetComponent <Egg>().GetColor());
                mEggAnimation.GetComponent <EggAnimationHandler>().AddPowerBlast(eggOnGrid.transform.position);
                AudioManager.Instance().PlaySFXPowerEgg();
            }
            else
            {
                Egg nearbyEgg = GetNearbyEgg(newEgg);
                if (nearbyEgg != null)
                {
                    crackedCount = PopEggsPowerEgg(nearbyEgg.GetColor());
                    mEggAnimation.GetComponent <EggAnimationHandler>().AddPowerBlast(nearbyEgg.transform.position);
                    AudioManager.Instance().PlaySFXPowerEgg();
                }
            }
            fallenCount = FallEggs();
            //Debug.Log(crackedCount + " and " + fallenCount);
            AddTotalScoreByCount(crackedCount, fallenCount);
            break;

        case (int)Defines.COLOR.SPECIAL_RAINBOW:
            //Debug.Log("OKKK --- "+bulletEgg.GetComponent<Bullet>().GetColor());
            if (eggOnGrid != null)
            {
                newEgg.SetColor(eggOnGrid.GetComponent <Egg>().GetColor());
            }
            else
            {
                int currentEgg = UnityEngine.Random.Range(0, Defines.EggCount);
                newEgg.SetColor(currentEgg);
            }
            newEgg.gameObject.SetActive(true);
            List <Egg> crackedEggRainbow = SpreadToAllNearbyEgg(newEgg);
            crackedCount = crackedEggRainbow.Count;
            fallenCount  = 0;
            if (crackedCount >= 3)
            {
                PopEggs(crackedEggRainbow, true);
                fallenCount = FallEggs();
                AddTotalScoreByCount(crackedCount, fallenCount);
                currentCombo++;
                uiAnimationObject.GetComponent <UIAnimationHandler>().ShowComboTextTimed(currentCombo, null, null);
            }
            else
            {
                if (currentCombo > 0)
                {
                    uiAnimationObject.GetComponent <UIAnimationHandler>().ShowComboTextTimed(0, null, null);
                }
                currentCombo = 0;
            }
            AudioManager.Instance().PlaySFXRainbowEgg();
            break;

        default:
            //Debug.Log("OKKK --- "+bulletEgg.GetComponent<Bullet>().GetColor());
            newEgg.SetColor(refBullet.GetComponent <Bullet>().GetColor());
            newEgg.gameObject.SetActive(true);
            List <Egg> crackedEgg = SpreadToAllNearbyEgg(newEgg);
            crackedCount = crackedEgg.Count;
            fallenCount  = 0;
            if (crackedCount >= 3)
            {
                PopEggs(crackedEgg);
                fallenCount = FallEggs();
                AddTotalScoreByCount(crackedCount, fallenCount);
                AudioManager.Instance().PlaySFXEggBreak();
                currentCombo++;
                uiAnimationObject.GetComponent <UIAnimationHandler>().ShowComboTextTimed(currentCombo, null, null);
            }
            else
            {
                AudioManager.Instance().PlaySFXEggHit();
                if (currentCombo > 0)
                {
                    uiAnimationObject.GetComponent <UIAnimationHandler>().ShowComboTextTimed(0, null, null);
                }
                currentCombo = 0;
            }
            break;
        }
    }