Beispiel #1
0
        public void TogglePersistence(string tag, bool state)
        {
            if (!soundObject.tag.Equals(tag))
            {
                //Debug.Log($"Can Play FX ?: {state}");
                PersistenceController.playerData.soundConfig.canPlayFX = state; //? Pq não funciona ?
            }
            else
            {
                //Debug.Log($"Can Play Music ?: {state}");
                PersistenceController.playerData.soundConfig.canPlayMusic = state;
            }

            PersistenceController.SavePlayerData();
        }
Beispiel #2
0
        /// <summary>
        /// Activates a power up from a list of available power ups
        /// </summary>
        /// <param name="setValue">The index numebr of the powerup to activate</param>
        IEnumerator ActivatePowerup(int powerupIndex)
        {
            //If there is already a similar powerup running, refill its duration timer
            if (powerups[powerupIndex].duration > 0)
            {
                //Refil the duration of the powerup to maximum
                powerups[powerupIndex].duration = powerups[powerupIndex].durationMax;

                // Add to the current power up streak count
                currentPowerUpStreak++;
            }
            else //Otherwise, activate the power up functions
            {
                //Activate the powerup icon
                if (powerups[powerupIndex].icon)
                {
                    powerups[powerupIndex].icon.gameObject.SetActive(true);
                }

                //Run up to two start functions from the gamecontroller
                if (powerups[powerupIndex].startFunction != string.Empty)
                {
                    SendMessage(powerups[powerupIndex].startFunction, powerups[powerupIndex].startParamater);
                }

                //Fill the duration timer to maximum
                powerups[powerupIndex].duration = powerups[powerupIndex].durationMax;

                //Count down the duration of the powerup
                while (powerups[powerupIndex].duration > 0)
                {
                    yield return(new WaitForSeconds(Time.deltaTime));

                    powerups[powerupIndex].duration -= Time.deltaTime;

                    //Animate the powerup timer graphic using fill amount
                    if (powerups[powerupIndex].icon)
                    {
                        powerups[powerupIndex].icon.Find("FillAmount").GetComponent <Image>().fillAmount = powerups[powerupIndex].duration / powerups[powerupIndex].durationMax;
                    }
                }

                //Run up to two end functions from the gamecontroller
                if (powerups[powerupIndex].endFunction != string.Empty)
                {
                    SendMessage(powerups[powerupIndex].endFunction, powerups[powerupIndex].endParamater);
                }

                //Deactivate the powerup icon
                if (powerups[powerupIndex].icon)
                {
                    powerups[powerupIndex].icon.gameObject.SetActive(false);
                }

                // Reset the current power up streak
                currentPowerUpStreak = 0;
            }

            // Add to the powerup count
            totalPowerups++;

            //Add this info to the persistence data
            PersistenceController.playerData.playerStats.powerupsCollected += totalPowerups;
            Debug.Log($"Powerups Collected: {PersistenceController.playerData.playerStats.powerupsCollected}");
            PersistenceController.SavePlayerData();
        }
Beispiel #3
0
        //This function handles the game over event
        IEnumerator GameOver(float delay)
        {
            //Go through all the powerups and nullify their timers, making them end
            for (index = 0; index < powerups.Length; index++)
            {
                //Set the duration of the powerup to 0
                powerups[index].duration = 0;
            }

            yield return(new WaitForSeconds(delay));

            //If there is a source and a sound, play it from the source
            if (soundSource && soundGameOver)
            {
                soundSource.GetComponent <AudioSource>().PlayOneShot(soundGameOver);
            }

            isGameOver = true;

            //Hide the pause screen and the game screen
            if (pauseCanvas)
            {
                pauseCanvas.gameObject.SetActive(false);
            }
            if (gameCanvas)
            {
                gameCanvas.gameObject.SetActive(false);
            }
            //Show the game over screen
            if (gameOverCanvas)
            {
                //Show the game over screen
                gameOverCanvas.gameObject.SetActive(true);

                //Write the score text
                gameOverCanvas.Find("TextScore").GetComponent <Text>().text = "SCORE " + score.ToString();

                //Check if we got a high score
                if (score > highScore)
                {
                    highScore = score;
                    PersistenceController.CheckHighscore(highScore);
                }

                //Write the high sscore text
                gameOverCanvas.Find("TextHighScore").GetComponent <Text>().text = "HIGH SCORE " + highScore.ToString();


                // Show bonus button

                bonusCanvas.gameObject.SetActive(Advertisement.IsReady());
            }

            //Check if the longest streak is greater than the persisted one, if it is, persist it
            int persistedLongestStreak = PersistenceController.playerData.playerStats.longestStreak;

            if (longestStreak > persistedLongestStreak)
            {
                Debug.Log($"New Longest Streak Persisted ! (old: {persistedLongestStreak}, new: {longestStreak})");
                PersistenceController.playerData.playerStats.longestStreak = longestStreak;
                PersistenceController.SavePlayerData();
            }
        }