Beispiel #1
0
    private static void UI_OnMainMenu()
    {
        //Debug.Log("This is the 'UI_OnMainMenu' method contained in the GameManager class.");

        isPaused = !isPaused;
        TogglePause(false);
        Player_OnPlayerIsDead(false);
        OnToggleSuccessPanel?.Invoke(false);
        OnToggleGameFinishedPanel(false);

        SceneManager.LoadScene(LevelInformation.Levels[0].name);
    }
Beispiel #2
0
    private static void UI_OnRetry()
    {
        //Debug.Log("This is 'UI_OnRetry' contained in GameManager class.");

        isPaused = !isPaused;
        TogglePause(false);
        Player_OnPlayerIsDead(false);
        OnToggleSuccessPanel?.Invoke(false);
        OnToggleGameFinishedPanel(false);

        SceneManager.LoadScene(LevelInformation.Levels[SceneManager.GetActiveScene().buildIndex].name);
    }
Beispiel #3
0
    private static void Collectible_OnPickUp(Collectible collectible, Collectible.CollectibleType pickupType)
    {
        //Debug.Log("This is the pick up function on GameManager.");
        switch (pickupType)
        {
        case Collectible.CollectibleType.GOLD:
            if (!StarConditions[0])
            {
                StarConditions[0] = true;
                if (SoundManager.MusicSource.isPlaying)
                {
                    SoundManager.MusicSource.Stop();
                }
            }
            break;

        case Collectible.CollectibleType.GEM:
            if (GemsInCurrentLevel.Contains(collectible))
            {
                GemsInCurrentLevel.Remove(collectible);
                GemsAcquired += 1;
            }

            //SoundManager.PlaySound(SoundManager.GemPickup);

            if (GemsInCurrentLevel.Count == 0)
            {
                StarConditions[1] = true;
            }
            break;
        }

        // This is what happens when the gold has been acquired. (Handle player success)
        if (StarConditions[0])
        {
            Player.SetState(CustomPlayerController.PlayerStates.SUCCESS);
            // Stop the level music

            // When the level is complete but the level did not contain any GEMS, the star condition is automatically fulfilled.
            if (GemsInCurrentLevel.Count == 0 && !StarConditions[1])
            {
                StarConditions[1] = true;
            }

            if (Player.curPlayerHealth >= 20)
            {
                StarConditions[2] = true;
            }

            for (int i = 0; i < StarConditions.Length; i++)
            {
                if (StarConditions[i])
                {
                    StarsAcquired++;
                }
            }

            switch (StarsAcquired)
            {
            case 1:
                SoundManager.PlaySound(SoundManager.Win1);
                break;

            case 2:
                SoundManager.PlaySound(SoundManager.Win2);
                break;

            case 3:
                SoundManager.PlaySound(SoundManager.Win3);
                break;
            }

            // assign collected gems to the level
            if (LevelInformation.Levels[LevelIndex].gemsAcquired < GemsAcquired)
            {
                LevelInformation.Levels[LevelIndex].gemsAcquired = GemsAcquired;
            }

            // Assign the awarded stars to the level and unlock the next level.
            //LevelInformation.Levels[LevelIndex].stars = (Level.LevelStars)StarsAcquired;
            if (LevelInformation.Levels[LevelIndex].stars < (Level.LevelStars)StarsAcquired)
            {
                LevelInformation.Levels[LevelIndex].stars = (Level.LevelStars)StarsAcquired;
            }

            if (LevelIndex != LevelInformation.Levels.Length - 1)
            {
                //Debug.Log($"Level Index : {LevelIndex}. Levels Length: {LevelInformation.Levels.Length}.");
                if (LevelInformation.Levels[LevelIndex + 1].levelLocked)
                {
                    LevelInformation.Levels[LevelIndex + 1].levelLocked = false;
                }

                OnToggleSuccessPanel?.Invoke(true);
            }
            else
            {
                OnToggleGameFinishedPanel?.Invoke(true);
            }

            SaveSystem.SaveGame();
        }
    }