Exemple #1
0
    IEnumerator LoseTime()
    {
        while (!isPaused)
        {
            yield return(new WaitForSeconds(0.5f));

            ScoreKeeper.timeLeft--;
            if (ScoreKeeper.timeLeft == 100)
            {
                bgMusic.LowTime();
            }

            if (ScoreKeeper.timeLeft == 0)
            {
                ScoreKeeper.livesLeft -= 1;
                SoundFXScript.playDeathSound();
                yield return(new WaitForSeconds(3));

                LevelManager.ReloadScene();
            }

            // Stops timer when player finishes level or dies
            if (ScoreKeeper.isFinished || ScoreKeeper.isDead)
            {
                ScoreKeeper.isFinished = false;
                ScoreKeeper.isDead     = false;
                yield break;
            }
        }

        while (isPaused)
        {
            yield return(null);
        }
    }
Exemple #2
0
    public IEnumerator DIE()
    {
        if (bonus == false)
        {
            health = health - 1;
            ScoreKeeper.livesLeft = health;
            Power_up.power_type   = 0;
        }

        if (health >= 1)
        {
            if (!gameObject.name.Contains("BonusExit"))
            {
                SoundFXScript.playDeathSound();
                yield return(new WaitForSeconds(3));
            }
            ScoreKeeper.resetTimer();
            Application.LoadLevel(respawn);
            yield return(null);
        }
        if (health <= 0)
        {
            yield return(new WaitForSeconds(3));

            LoadLevelScript.loadNewGame();
            Application.LoadLevel(DEAD);
            yield return(null);
        }
    }
Exemple #3
0
 private void OnTriggerEnter2D(Collider2D col)
 {
     //check if collied with a power up and update the power type accordingly
     if (col.gameObject.tag == "Power Up")
     {
         if (col.gameObject.name.Contains("Coin"))
         {
             ScoreKeeper.addCoins(1);
             ScoreKeeper.addPoints(100);
         }
         else
         {
             ScoreKeeper.addPoints(250);
         }
         if (col.gameObject.name.Contains("Red Mushroom") && power_type == 0)
         {
             power_type = 1;
             growBigger();
         }
         if (col.gameObject.name.Contains("Flower") && power_type == 1)
         {
             power_type = 2;
             fireUp();
         }
         // if we pick up a star, then we become invincible
         if (col.gameObject.name.Contains("Star"))
         {
             becomeInvincible();
         }
         //destroy the collectible, then get our power
         Destroy(col.gameObject);
     }
     //check if collided with enemy
     if (col.gameObject.tag == "Enemy")
     {
         // if we have a power up, we return to normal
         if (power_type > 0 && !isInvincible)
         {
             SoundFXScript.playShrinkSound();
             RevertBackToNormalAfterCollideWithEnemy();
             power_type = 0;
         }
         if (!isInvincible && power_type == 0 && !death.hasDied)
         {
             death.hasDied      = true;
             ScoreKeeper.isDead = true;
             Destroy(gameObject);
             Instantiate(Mario_Die, transform.position, new Quaternion(0, 0, 0, 0));
             death.StartCoroutine(death.DIE());
         }
     }
 }
Exemple #4
0
 public static void addCoins(int newCoins)
 {
     if (coins + newCoins >= 100)
     {
         addLife();
         coins += newCoins - 100;
         SoundFXScript.OneUp();
     }
     else
     {
         coins += newCoins;
     }
 }