Ejemplo n.º 1
0
    IEnumerator CoinCreation()
    {
        //Debug.Log("test0");
        WaitForSeconds waitForSeconds;

        while (true)
        {
            LevelProps currentLevel = levelList[GetCurrentLevel() - 1].GetComponent <LevelProps>();
            if (currentLevel)
            {
                float createSec = 0;
                //float randomSec;

                //randomSec = Random.Range(0, currentLevel.obstacleCreateInSec);
                createSec = currentLevel.coinCreateInSec;

                waitForSeconds = new WaitForSeconds(createSec);
            }
            else
            {
                waitForSeconds = new WaitForSeconds(defaultCoinCreateInSeconds);
            }

            // Place your method calls
            yield return(waitForSeconds);

            CreateCoin(GetCurrentLevel());
        }
    }
Ejemplo n.º 2
0
    private void CreateCoin(int currentLevelIndex)
    {
        LevelProps currentLevel = levelList[currentLevelIndex - 1].GetComponent <LevelProps>();

        coinsLimitReached = false;
        if (coinsCreated.ContainsKey(currentLevelIndex))
        {
            if ((int)coinsCreated[currentLevelIndex] >= currentLevel.coinsCreateTotal)
            {
                coinsLimitReached = true;
            }
        }

        if (!coinsLimitReached && checkIfCoinCreatable())
        {
            int        posYFactor           = Random.Range(0, 2);
            Vector2    coinCreationPosition = new Vector2(transform.position.x, transform.position.y + (posYFactor * 3.5f));
            GameObject newCoin = Instantiate(coin, coinCreationPosition, Quaternion.identity);
            if (coinsCreated.ContainsKey(currentLevelIndex))
            {
                coinsCreated[currentLevelIndex] = (int)coinsCreated[currentLevelIndex] + 1;
            }
            else
            {
                coinsCreated.Add(currentLevelIndex, (int)1);
            }

            newCoin.transform.parent = mainPath.transform;
        }
    }
Ejemplo n.º 3
0
    public GhostFrightSession(LevelProps levelProps)
    {
        _amountOfGhostsEaten = 0;
        _timeLeft            = levelProps.FrightGhostTime.Value;

        var flashesLeft = levelProps.FrightGhostFlashes;

        _timeLeftToStartFlashing = _timeLeft -
                                   TimeSpan.FromMilliseconds(flashesLeft * _eachFlashDurationMs.TotalMilliseconds);
        _timer = new(
            _eachFlashDurationMs, () => _tickTock = !_tickTock);
    }
Ejemplo n.º 4
0
    // Start is called before the first frame update
    void Start()
    {
        levelsStartSec = new List <float>();
        foreach (GameObject level in levelList)
        {
            LevelProps levelProperties = level.GetComponent <LevelProps>();
            levelsStartSec.Add(levelProperties.levelStartSec);
        }
        levelsStartSec.Sort();

        StartCoroutine("CoinCreation");
    }
Ejemplo n.º 5
0
    private void CreateParachute(int currentLevelIndex)
    {
        int        randomParachuteIndex;
        LevelProps currentLevel = levelList[currentLevelIndex - 1].GetComponent <LevelProps>();

        randomParachuteIndex = Random.Range(0, currentLevel.levelParachutes.Length);
        GameObject newParachute = Instantiate(currentLevel.levelParachutes[randomParachuteIndex]);

        Object.Destroy(newParachute, 5f);
        //newParachute.transform.parent = mainPath.transform;
        return;
    }
Ejemplo n.º 6
0
    IEnumerator ObstacleCreation()
    {
        //Debug.Log("test0");
        WaitForSeconds waitForSeconds;

        while (true)
        {
            LevelProps currentLevel = levelList[GetCurrentLevel() - 1].GetComponent <LevelProps>();
            if (currentLevel)
            {
                float createSec = 0;
                float randomSec;

                randomSec = Random.Range(0, currentLevel.obstacleCreateInSec);


                if (isFirstRun)
                {
                    createSec  = firstObsCreateInSeconds;
                    isFirstRun = false;
                }
                else
                {
                    if (Mathf.CeilToInt(randomSec) % 2 == 0)
                    {
                        createSec = currentLevel.obstacleCreateInSec + randomSec * 0.2f;
                    }
                    else
                    {
                        createSec = currentLevel.obstacleCreateInSec - randomSec * 0.2f;
                    }
                }

                //Debug.Log("create sec: " + createSec);

                waitForSeconds = new WaitForSeconds(createSec);
            }
            else
            {
                waitForSeconds = new WaitForSeconds(defaultObsCreateInSeconds);
            }

            // Place your method calls
            yield return(waitForSeconds);

            if (currentLevel.levelObstacles.Length > 0)
            {
                CreateObstacle(GetCurrentLevel());
            }
        }
    }
Ejemplo n.º 7
0
    private CollectableItem GetRandomBonus()
    {
        LevelProps levelProps = obstacleSpawner.GetLevelProps();

        int bonusCount = levelProps.levelParachutes.Length;

        CollectableItem randomCollectable = levelProps.levelParachutes[UnityEngine.Random.Range(0, bonusCount)]
                                            .GetComponent <CollectableItem>();

        while (randomCollectable.collectableType == CollectableItem.CollectableType.RandomCollectable)
        {
            randomCollectable = levelProps.levelParachutes[UnityEngine.Random.Range(0, bonusCount)]
                                .GetComponent <CollectableItem>();
        }

        return(randomCollectable);
    }
Ejemplo n.º 8
0
    IEnumerator ParachuteCreation()
    {
        WaitForSeconds waitForSeconds;

        while (true)
        {
            LevelProps currentLevel = levelList[GetCurrentLevel() - 1].GetComponent <LevelProps>();
            if (currentLevel)
            {
                float createSec = 0;
                float randomSec = Random.Range(0, currentLevel.parachuteCreateInSec);

                if (Mathf.CeilToInt(randomSec) % 2 == 0)
                {
                    createSec = currentLevel.parachuteCreateInSec + randomSec * 0.2f;
                }
                else
                {
                    createSec = currentLevel.parachuteCreateInSec - randomSec * 0.2f;
                }

                waitForSeconds = new WaitForSeconds(createSec);
            }
            else
            {
                waitForSeconds = new WaitForSeconds(defaultParachuteCreateInSeconds);
            }

            // Place your method calls
            yield return(waitForSeconds);

            if (currentLevel.levelParachutes.Length > 0)
            {
                CreateParachute(GetCurrentLevel());
            }
        }
    }
Ejemplo n.º 9
0
    private void CreateObstacle(int currentLevelIndex)
    {
        int randomObstacleIndex;

        Debug.Log("CreateObsCurrLevel:" + currentLevelIndex.ToString());
        LevelProps currentLevel = levelList[currentLevelIndex - 1].GetComponent <LevelProps>();

        randomObstacleIndex = Random.Range(0, currentLevel.levelObstacles.Length);
        //Vector2 creationPosition = new Vector2(transform.position.x, currentLevel.obstaclePosY[randomObstacleIndex]);
        int posYChange = 0;

        if (currentLevel.levelObstacles[randomObstacleIndex].name.Equals("Bird"))
        {
            posYChange = Random.Range(-3, 4);
        }
        Vector2    creationPosition = new Vector2(transform.position.x, currentLevel.levelObstacles[randomObstacleIndex].transform.position.y + posYChange);
        GameObject newObstacle      = Instantiate(currentLevel.levelObstacles[randomObstacleIndex], creationPosition, Quaternion.identity);

        bool      createObstacleWithPotion = false;
        Transform collectableItemPos       = null;

        if (currentLevel.levelPotions.Length > 0 && currentLevel.potionsCreateTotal > 0)
        {
            collectableItemPos = newObstacle.transform.Find("collectablepos");

            if (collectableItemPos)
            {
                if (potionsCreated.ContainsKey(currentLevelIndex))
                {
                    if ((int)potionsCreated[currentLevelIndex] < currentLevel.potionsCreateTotal)
                    {
                        createObstacleWithPotion = true;
                    }
                }
                else
                {
                    createObstacleWithPotion = true;
                }
            }
        }

        if (createObstacleWithPotion)
        {
            int        randomPotionIndex      = Random.Range(0, currentLevel.levelPotions.Length);
            Vector2    potionCreationPosition = new Vector2(collectableItemPos.position.x, collectableItemPos.position.y);
            GameObject newPotion = Instantiate(currentLevel.levelPotions[randomPotionIndex], potionCreationPosition, Quaternion.identity);
            newPotion.transform.parent = newObstacle.transform;
            if (potionsCreated.ContainsKey(currentLevelIndex))
            {
                potionsCreated[currentLevelIndex] = (int)potionsCreated[currentLevelIndex] + 1;
            }
            else
            {
                potionsCreated.Add(currentLevelIndex, (int)1);
            }
            Debug.Log("xxxxx:" + potionsCreated[currentLevelIndex].ToString());
        }

        newObstacle.transform.parent = mainPath.transform;
        return;
    }