Esempio n. 1
0
        void Start()
        {
            spawnCurrency       = false;
            spawnDoubleCurrency = false;

            nextSpawnDif = SpawnDifficulty.Casual;

            dif1TimesIncreased = 0;
            dif2TimesIncreased = 0;
        }
Esempio n. 2
0
        void Update()
        {
            if (Time.time >= fadeTime)
            {
                gameManagerMaster.CallEventCycleBackground();
                fadeTime += backgroundFadeTime;
            }

            switch (GameManager_Master.gameState)
            {
            case GameState.Menu:
                break;

            case GameState.Playing:
                if (numberOfObjectsToSpawn > 0)
                {
                    if (!testMode)
                    {
                        switch (nextSpawnDif)
                        {
                        case SpawnDifficulty.Casual:
                            nextSpawn = Random.Range(0, totalNumberCasual);
                            if (platformPool[nextSpawn].activeSelf == true)
                            {
                                //Already spawned in the world so need different one.
                                nextSpawnDif = (SpawnDifficulty)WeightedRandom(spawnDifChance);
                                break;
                            }
                            else
                            {
                                //Do we spawn premium currency with this platform spawn
                                spawnCurrency       = Random.Range(0, 100) <= chanceToSpawnPremium ? true : false;
                                spawnDoubleCurrency = Random.Range(0, 100) <= chanceToSpawnDoublePremium ? true : false;

                                //Get next spawn X position
                                if (!firstSpawn)
                                {
                                    nextSpawnLocation.x = platformPoolsComponents[lastSpawn].platformCollider.bounds.max.x +
                                                          Random.Range(minJumpDistance, maxJumpDistance) +
                                                          platformPoolsComponents[nextSpawn].platformCollider.size.x / 2 * platformPool[nextSpawn].transform.localScale.x;
                                }
                                else
                                {
                                    nextSpawnLocation.x = lastManuallyPlacedObject.GetComponent <BoxCollider2D>().bounds.max.x +
                                                          Random.Range(minJumpDistance, maxJumpDistance) +
                                                          platformPoolsComponents[nextSpawn].platformCollider.size.x / 2 * platformPool[nextSpawn].transform.localScale.x;

                                    firstSpawn = false;
                                }

                                //Get next spawn Y position
                                nextSpawnLocation.y = platformPoolsComponents[nextSpawn].platformCollider.size.y / 2 * platformPool[nextSpawn].transform.localScale.y;

                                //set position and activate.
                                platformPool[nextSpawn].transform.position = nextSpawnLocation;
                                platformPool[nextSpawn].SetActive(true);

                                //Picks a random Dif to be spawned next based on weights.
                                nextSpawnDif = (SpawnDifficulty)WeightedRandom(spawnDifChance);
                                numberOfObjectsToSpawn--;
                                lastSpawn = nextSpawn;
                                platforms.Add(platformPool[lastSpawn]);
                            }

                            break;

                        case SpawnDifficulty.Easy:
                            nextSpawn = Random.Range(totalNumberCasual, totalNumberCasual + totalNumberEasy);
                            if (platformPool[nextSpawn].activeSelf == true)
                            {
                                //Already spawned in the world so need different one.
                                nextSpawnDif = (SpawnDifficulty)WeightedRandom(spawnDifChance);
                                break;
                            }
                            else
                            {
                                //Do we spawn premium currency with this platform spawn
                                spawnCurrency       = Random.Range(0, 100) <= chanceToSpawnPremium ? true : false;
                                spawnDoubleCurrency = Random.Range(0, 100) <= chanceToSpawnDoublePremium ? true : false;

                                //Get next spawn X position
                                if (!firstSpawn)
                                {
                                    nextSpawnLocation.x = platformPoolsComponents[lastSpawn].platformCollider.bounds.max.x +
                                                          Random.Range(minJumpDistance, maxJumpDistance) +
                                                          platformPoolsComponents[nextSpawn].platformCollider.size.x / 2 * platformPool[nextSpawn].transform.localScale.x;
                                }
                                else
                                {
                                    nextSpawnLocation.x = lastManuallyPlacedObject.GetComponent <BoxCollider2D>().bounds.max.x +
                                                          Random.Range(minJumpDistance, maxJumpDistance) +
                                                          platformPoolsComponents[nextSpawn].platformCollider.size.x / 2 * platformPool[nextSpawn].transform.localScale.x;

                                    firstSpawn = false;
                                }

                                //Get next spawn Y position
                                nextSpawnLocation.y = platformPoolsComponents[nextSpawn].platformCollider.size.y / 2 * platformPool[nextSpawn].transform.localScale.y;

                                //set position and activate.
                                platformPool[nextSpawn].transform.position = nextSpawnLocation;
                                platformPool[nextSpawn].SetActive(true);

                                //Picks a random Dif to be spawned next based on weights.
                                nextSpawnDif = (SpawnDifficulty)WeightedRandom(spawnDifChance);
                                numberOfObjectsToSpawn--;
                                lastSpawn = nextSpawn;
                                platforms.Add(platformPool[lastSpawn]);
                            }

                            break;

                        case SpawnDifficulty.Medium:
                            nextSpawn = Random.Range(totalNumberCasual + totalNumberEasy, totalNumberCasual + totalNumberEasy + totalNumberMedium);
                            if (platformPool[nextSpawn].activeSelf == true)
                            {
                                //Already spawned in the world so need different one.
                                nextSpawnDif = (SpawnDifficulty)WeightedRandom(spawnDifChance);
                                break;
                            }
                            else
                            {
                                //Do we spawn premium currency with this platform spawn
                                spawnCurrency       = Random.Range(0, 100) <= chanceToSpawnPremium ? true : false;
                                spawnDoubleCurrency = Random.Range(0, 100) <= chanceToSpawnDoublePremium ? true : false;

                                //Get next spawn X position
                                if (!firstSpawn)
                                {
                                    nextSpawnLocation.x = platformPoolsComponents[lastSpawn].platformCollider.bounds.max.x +
                                                          Random.Range(minJumpDistance, maxJumpDistance) +
                                                          platformPoolsComponents[nextSpawn].platformCollider.size.x / 2 * platformPool[nextSpawn].transform.localScale.x;
                                }
                                else
                                {
                                    nextSpawnLocation.x = lastManuallyPlacedObject.GetComponent <BoxCollider2D>().bounds.max.x +
                                                          Random.Range(minJumpDistance, maxJumpDistance) +
                                                          platformPoolsComponents[nextSpawn].platformCollider.size.x / 2 * platformPool[nextSpawn].transform.localScale.x;

                                    firstSpawn = false;
                                }

                                //Get next spawn Y position
                                nextSpawnLocation.y = platformPoolsComponents[nextSpawn].platformCollider.size.y / 2 * platformPool[nextSpawn].transform.localScale.y;

                                //set position and activate.
                                platformPool[nextSpawn].transform.position = nextSpawnLocation;
                                platformPool[nextSpawn].SetActive(true);

                                //Picks a random Dif to be spawned next based on weights.
                                nextSpawnDif = (SpawnDifficulty)WeightedRandom(spawnDifChance);
                                numberOfObjectsToSpawn--;
                                lastSpawn = nextSpawn;
                                platforms.Add(platformPool[lastSpawn]);
                            }

                            break;

                        case SpawnDifficulty.Hard:
                            nextSpawn = Random.Range(totalNumberCasual + totalNumberEasy + totalNumberMedium, totalNumberCasual + totalNumberEasy + totalNumberMedium + totalNumberHard);
                            if (platformPool[nextSpawn].activeSelf == true)
                            {
                                //Already spawned in the world so need different one.
                                nextSpawnDif = (SpawnDifficulty)WeightedRandom(spawnDifChance);
                                break;
                            }
                            else
                            {
                                //Do we spawn premium currency with this platform spawn
                                spawnCurrency       = Random.Range(0, 100) <= chanceToSpawnPremium ? true : false;
                                spawnDoubleCurrency = Random.Range(0, 100) <= chanceToSpawnDoublePremium ? true : false;

                                //Get next spawn X position
                                if (!firstSpawn)
                                {
                                    nextSpawnLocation.x = platformPoolsComponents[lastSpawn].platformCollider.bounds.max.x +
                                                          Random.Range(minJumpDistance, maxJumpDistance) +
                                                          platformPoolsComponents[nextSpawn].platformCollider.size.x / 2 * platformPool[nextSpawn].transform.localScale.x;
                                }
                                else
                                {
                                    nextSpawnLocation.x = lastManuallyPlacedObject.GetComponent <BoxCollider2D>().bounds.max.x +
                                                          Random.Range(minJumpDistance, maxJumpDistance) +
                                                          platformPoolsComponents[nextSpawn].platformCollider.size.x / 2 * platformPool[nextSpawn].transform.localScale.x;

                                    firstSpawn = false;
                                }

                                //Get next spawn Y position
                                nextSpawnLocation.y = platformPoolsComponents[nextSpawn].platformCollider.size.y / 2 * platformPool[nextSpawn].transform.localScale.y;

                                //set position and activate.
                                platformPool[nextSpawn].transform.position = nextSpawnLocation;
                                platformPool[nextSpawn].SetActive(true);

                                //Picks a random Dif to be spawned next based on weights.
                                nextSpawnDif = (SpawnDifficulty)WeightedRandom(spawnDifChance);
                                numberOfObjectsToSpawn--;
                                lastSpawn = nextSpawn;
                                platforms.Add(platformPool[lastSpawn]);
                            }

                            break;

                        case SpawnDifficulty.BookItPro:
                            nextSpawn = Random.Range(totalNumberCasual + totalNumberEasy + totalNumberMedium + totalNumberHard, platformPool.Length);
                            if (platformPool[nextSpawn].activeSelf == true)
                            {
                                //Already spawned in the world so need different one.
                                nextSpawnDif = (SpawnDifficulty)WeightedRandom(spawnDifChance);
                                break;
                            }
                            else
                            {
                                //Do we spawn premium currency with this platform spawn
                                spawnCurrency       = Random.Range(0, 100) <= chanceToSpawnPremium ? true : false;
                                spawnDoubleCurrency = Random.Range(0, 100) <= chanceToSpawnDoublePremium ? true : false;

                                //Get next spawn X position
                                if (!firstSpawn)
                                {
                                    nextSpawnLocation.x = platformPoolsComponents[lastSpawn].platformCollider.bounds.max.x +
                                                          Random.Range(minJumpDistance, maxJumpDistance) +
                                                          platformPoolsComponents[nextSpawn].platformCollider.size.x / 2 * platformPool[nextSpawn].transform.localScale.x;
                                }
                                else
                                {
                                    nextSpawnLocation.x = lastManuallyPlacedObject.GetComponent <BoxCollider2D>().bounds.max.x +
                                                          Random.Range(minJumpDistance, maxJumpDistance) +
                                                          platformPoolsComponents[nextSpawn].platformCollider.size.x / 2 * platformPool[nextSpawn].transform.localScale.x;

                                    firstSpawn = false;
                                }

                                //Get next spawn Y position
                                nextSpawnLocation.y = platformPoolsComponents[nextSpawn].platformCollider.size.y / 2 * platformPool[nextSpawn].transform.localScale.y;

                                //set position and activate.
                                platformPool[nextSpawn].transform.position = nextSpawnLocation;
                                platformPool[nextSpawn].SetActive(true);

                                //Picks a random Dif to be spawned next based on weights.
                                nextSpawnDif = (SpawnDifficulty)WeightedRandom(spawnDifChance);
                                numberOfObjectsToSpawn--;
                                lastSpawn = nextSpawn;
                                platforms.Add(platformPool[lastSpawn]);
                            }

                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        spawnCurrency       = true;
                        spawnDoubleCurrency = true;

                        if (testPlatform.GetComponent <BoxCollider2D>().offset.x == 0)
                        {
                            nextSpawnLocation.x = lastManuallyPlacedObject.GetComponent <BoxCollider2D>().bounds.max.x +
                                                  Random.Range(minJumpDistance, maxJumpDistance) +
                                                  testPlatform.GetComponent <BoxCollider2D>().size.x / 2 * testPlatform.transform.localScale.x;
                        }
                        else
                        {
                            nextSpawnLocation.x = lastManuallyPlacedObject.GetComponent <BoxCollider2D>().bounds.max.x +
                                                  Random.Range(minJumpDistance, maxJumpDistance);
                        }

                        nextSpawnLocation.y = testPlatform.GetComponent <BoxCollider2D>().size.y / 2 * testPlatform.transform.localScale.y;

                        //Spawns the object and stores it so its location can be used for the next object.
                        lastManuallyPlacedObject = Instantiate(testPlatform, nextSpawnLocation, Quaternion.identity);
                        AddObjectToPlatformList(lastManuallyPlacedObject);
                        numberOfObjectsToSpawn--;
                    }


                    if (spawnCurrency && premiumCurrency != null)
                    {
                        if (!testMode)
                        {
                            int spawnDif = WeightedRandom(weightedPremiumSpawnDif);

                            if (spawnDif == 0)
                            {
                                if (platformPoolsComponents[nextSpawn].easyPagePosition != null)
                                {
                                    platformPoolsComponents[lastSpawn].premiumCurrency = Instantiate(premiumCurrency, platformPoolsComponents[nextSpawn].easyPagePosition.transform.position, Quaternion.identity);
                                }
                            }
                            else if (spawnDif == 1)
                            {
                                if (platformPoolsComponents[nextSpawn].mediumPagePosition != null)
                                {
                                    platformPoolsComponents[lastSpawn].premiumCurrency = Instantiate(premiumCurrency, platformPoolsComponents[nextSpawn].mediumPagePosition.transform.position, Quaternion.identity);
                                }
                            }
                            else
                            {
                                if (platformPoolsComponents[nextSpawn].hardPagePosition != null)
                                {
                                    platformPoolsComponents[lastSpawn].premiumCurrency = Instantiate(premiumCurrency, platformPoolsComponents[nextSpawn].hardPagePosition.transform.position, Quaternion.identity);
                                }
                            }
                        }
                        else
                        {
                            if (spawnCurrency && premiumCurrency != null)
                            {
                                int spawnDif = WeightedRandom(weightedPremiumSpawnDif);

                                if (spawnDif == 0)
                                {
                                    if (lastManuallyPlacedObject.transform.Find("easyspawn") != null)
                                    {
                                        Instantiate(premiumCurrency, lastManuallyPlacedObject.transform.Find("easyspawn").transform.position, Quaternion.identity).transform.SetParent(lastManuallyPlacedObject.transform);
                                    }
                                }
                                else if (spawnDif == 1)
                                {
                                    if (lastManuallyPlacedObject.transform.Find("mediumspawn") != null)
                                    {
                                        Instantiate(premiumCurrency, lastManuallyPlacedObject.transform.Find("mediumspawn").transform.position, Quaternion.identity).transform.SetParent(lastManuallyPlacedObject.transform);
                                    }
                                }
                                else
                                {
                                    if (lastManuallyPlacedObject.transform.Find("hardspawn") != null)
                                    {
                                        Instantiate(premiumCurrency, lastManuallyPlacedObject.transform.Find("hardspawn").transform.position, Quaternion.identity).transform.SetParent(lastManuallyPlacedObject.transform);
                                    }
                                }
                            }
                        }

                        spawnCurrency = false;
                    }

                    if (spawnDoubleCurrency && doublePremiumCurrency != null)
                    {
                        if (!testMode)
                        {
                            if (platformPoolsComponents[nextSpawn].extremePagePosition != null)
                            {
                                platformPoolsComponents[lastSpawn].premiumDoubleCurrency = Instantiate(doublePremiumCurrency, platformPoolsComponents[nextSpawn].extremePagePosition.transform.position, Quaternion.identity);
                            }
                        }
                        else
                        {
                            if (lastManuallyPlacedObject.transform.Find("extremespawn") != null)
                            {
                                Instantiate(doublePremiumCurrency, lastManuallyPlacedObject.transform.Find("extremespawn").transform.position, Quaternion.identity).transform.SetParent(lastManuallyPlacedObject.transform);
                            }
                        }

                        spawnDoubleCurrency = false;
                    }
                }

                break;

            case GameState.Paused:
                break;

            case GameState.GameOver:
                break;

            default:
                break;
            }
        }