Esempio n. 1
0
    public void AddPoints(int points)
    {
        score += points;
        var slot     = SaveLoadSystem.GetCurrentSlot();
        var dataSave = SaveLoadSystem.Get(slot);

        dataSave.score = score;
        SaveLoadSystem.Save(slot, dataSave);
    }
Esempio n. 2
0
    private void Start()
    {
        if (inMainMenu)
        {
            return;
        }

        var saveData = SaveLoadSystem.Get(SaveLoadSystem.GetCurrentSlot());

        gameObject.transform.SetPositionAndRotation(new Vector3(
                                                        saveData.positionX == 0 ? gameObject.transform.position.x : saveData.positionX,
                                                        saveData.positionY == 0 ? gameObject.transform.position.y : saveData.positionY,
                                                        gameObject.transform.position.z
                                                        ), Quaternion.identity);
    }
Esempio n. 3
0
    private void SaveGame()
    {
        var slot     = SaveLoadSystem.GetCurrentSlot();
        var saveData = SaveLoadSystem.Get(slot);

        saveData.positionX = player.position.x;
        saveData.positionY = player.position.y;
        var timeLimit = FindObjectOfType <ScoreSystem>()?.timeLimit;

        if (timeLimit.HasValue)
        {
            saveData.timeLimit = Mathf.CeilToInt(timeLimit.Value - Time.timeSinceLevelLoad);
        }
        SaveLoadSystem.Save(slot, saveData);
        FindObjectOfType <ModalScreenSystem>().Show("Game Saved!", "Close", () => { });
    }
Esempio n. 4
0
    private IEnumerator loadNextLevel()
    {
        // Wait timeDelay
        yield return(new WaitForSeconds(timeDelay));

        // Pause Game
        Time.timeScale = 0;

        // Save Game Progress
        var slotKey  = SaveLoadSystem.GetCurrentSlot();
        var saveData = SaveLoadSystem.Get(slotKey);

        saveData.positionX = 0;
        saveData.positionY = 0;
        saveData.timeLimit = 0;

        if (hasNextLevel)
        {
            saveData.level = nextLevelToLoad;
            SaveLoadSystem.Save(slotKey, saveData);

            // Show a winning message
            FindObjectOfType <ModalScreenSystem>().Show("LEVEL PASSED", "Next level", () =>
            {
                Time.timeScale = 1;
                // Load the level named as in the nextLevelToLoad variable.
                SceneManager.LoadScene($"Level{nextLevelToLoad.ToString()}");
            });
        }
        else
        {
            SaveLoadSystem.Save(slotKey, saveData);

            // Show a winning message
            FindObjectOfType <ModalScreenSystem>().Show("GAME FINISHED", "Exit", () =>
            {
                Time.timeScale = 1;
                // Load the level named as in the nextLevelToLoad variable.

                SceneManager.LoadScene("StartScreen");
            });
        }
    }
Esempio n. 5
0
    private void Start()
    {
        var saveData = SaveLoadSystem.Get(SaveLoadSystem.GetCurrentSlot());

        if (saveData != null)
        {
            score     = saveData.score;
            timeLimit = saveData.timeLimit > 0 ? saveData.timeLimit : timeLimit;
        }

        if (!scoreText)
        {
            Debug.LogError("Score Text not assigned to ScoreSystem");
            Destroy(this);
        }

        if (!scoreText)
        {
            Debug.LogError("Time Text not assigned to ScoreSystem");
            Destroy(this);
        }
    }