Ejemplo n.º 1
0
        private void SetupSaveSlotScreen()
        {
            for (int i = 0; i < slotTexts.Length; i++)
            {
                int slot = i; // to conserve the slot index in the OnClick attribute.

                if (SaveLoadManager.CheckSlot(i))
                {
                    // Load data of the slot.
                    PlayerProgress progress = SaveLoadManager.LoadPlayerProgress(slot);

                    // Update treasures found.
                    treasuresParent[i].SetActive(progress.treasuresFound.Count > 0);
                    // foreach treasure... display it.

                    // Update slot information.
                    slotTexts[i].text = "Slot " + (slot + 1).ToString() + " - " + 0 + "%"; // TODO load completion percent.

                    moreInformationTexts[i].text = "Time : " + GetTimeFormated(progress.timePlayed);

                    moreInformationTexts[i].gameObject.SetActive(true);
                }

                else
                {
                    treasuresParent[i].SetActive(false);
                    moreInformationTexts[i].gameObject.SetActive(false);

                    // Update slot information.
                    slotTexts[i].text = "Slot " + (slot + 1).ToString() + " - empty";
                }
            }
        }
Ejemplo n.º 2
0
        private void UpdateWorldMapHUD(GraphNode targetNode, PlayerProgress playerProgress)
        {
            // Update worldmap HUD
            LevelNode     ln        = targetNode as LevelNode;
            WorldNode     wn        = targetNode as WorldNode;
            LevelProgress progress  = null;
            LevelData     levelData = null;

            // Check what is the new node.
            string whatIsIt = "";

            if (ln)
            {
                levelData = ln.data;

                if (levelData.isSecretLevel)
                {
                    whatIsIt = "Secret level";
                }
                else
                {
                    whatIsIt = "Level " + (ln.worldIndex + 1) + "-" + (ln.levelIndex + 1);
                }

                // Try to get progress.
                playerProgress.worldProgress[ln.worldIndex].finishedLevels.TryGetValue(ln.levelIndex, out progress);
            }
            else if (wn)
            {
                whatIsIt = "Go to " + wn.worldDataTarget.worldname;
            }

            hudMgr.UpdateLevelPreview(whatIsIt, levelData, progress);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load save slot selected.
        /// </summary>
        public void LoadPlayerProgress(int selectedSlot)
        {
            saveSlotSelected = selectedSlot;

            playerProgress = SaveLoadManager.LoadPlayerProgress(saveSlotSelected);

            LoadWorldMap();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Save player progress of the specified save.
        /// </summary>
        /// <param name="progress">Current player progress.</param>
        /// <param name="slot">save slot.</param>
        public static void SavePlayerProgress(PlayerProgress progress, int slot)
        {
            BinaryFormatter bf     = new BinaryFormatter();
            FileStream      stream = new FileStream(Application.persistentDataPath + "/" + saveFileName + slot.ToString() + saveFileExtension, FileMode.Create);

            // Save current world and graph node of Boing and also states of each level.
            bf.Serialize(stream, progress);

            stream.Close();
        }
Ejemplo n.º 5
0
        private void NewGameThenStart()
        {
            // Create new progression.
            playerProgress = new PlayerProgress();

            // Create or replace old save.
            SaveLoadManager.SavePlayerProgress(playerProgress, saveSlotSelected);

            LoadWorldMap();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Setup map depending of the player progress.
        /// </summary>
        /// <param name="playerProgress"></param>
        public IEnumerator SetupMap(PlayerProgress playerProgress)
        {
            ChangeWorldMap(playerProgress.currentWorldIndex);

            yield return(new WaitForEndOfFrame());

            SetupGraph();

            UnlockPaths(playerProgress);

            GraphNode newNode = UpdateBoingPosition(playerProgress.currentNodeIndex);

            UpdateWorldMapHUD(newNode, playerProgress);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Interact with the current node where Boing is.
        /// </summary>
        /// <param name="playerProgress">Informations about the player.</param>
        public void InteractWithCurrentNode(PlayerProgress playerProgress)
        {
            GraphNode node = graph.Find(x => x.nodeIndex == playerProgress.currentNodeIndex);

            LevelNode ln = node as LevelNode;
            WorldNode wn = node as WorldNode;

            if (ln)
            {
                SwitchToNewLevel(ln);
            }
            else if (wn)
            {
                StartCoroutine(SwitchToNewWorld(wn));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Try to move from the node to the specified direction.
        /// </summary>
        public void TryToMove(PlayerProgress playerProgress, Direction direction)
        {
            GraphNode node = graph.Find(x => x.nodeIndex == playerProgress.currentNodeIndex);

            // Check all paths.
            foreach (GraphTransition t in node.linkedNodes)
            {
                // Check if a direction is correct and the associated path is unlocked.
                if (t.inputNeeded == direction && t.path.unlocked)
                {
                    // Move along this path.
                    GraphNode targetNode = graph.Find(x => x.nodeIndex == t.targetNodeindex);

                    StartCoroutine(UpdateBoingPosition(t.path, targetNode, playerProgress));
                }
            }
        }
Ejemplo n.º 9
0
        private IEnumerator UpdateBoingPosition(Path path, GraphNode targetNode, PlayerProgress playerProgress)
        {
            Vector2 targetPosition = targetNode.positionOnMap;

            IsTravelling = true;

            // Move Boing along the path if not null.
            if (path != null)
            {
                // Reverse path if the target node is the start of the path.
                List <Vector2> pathPoints = path.waypoints;
                if (pathPoints[0] == targetPosition)
                {
                    pathPoints.Reverse();
                }

                // Move along the path.
                foreach (Vector2 t in pathPoints)
                {
                    targetPosition    = t;
                    targetPosition.y += offset;

                    while (Vector2.Distance(boing.transform.position, targetPosition) >= Mathf.Epsilon)
                    {
                        boing.transform.position = Vector2.MoveTowards(boing.transform.position, targetPosition, boingSpeed * Time.deltaTime);
                        yield return(null);
                    }

                    boing.transform.position = targetPosition;
                }
            }

            // Teleport Boing to the target point.
            else
            {
                targetPosition.y        += offset;
                boing.transform.position = targetPosition;
            }

            IsTravelling = false;

            UpdateWorldMapHUD(targetNode, playerProgress);
            GameManager.instance.UpdateCurrentNodeOnWorld(targetNode.nodeIndex);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Load the player progress of the specified save.
        /// </summary>
        /// <param name="slot">save slot</param>
        /// <returns>Player progress</returns>
        public static PlayerProgress LoadPlayerProgress(int slot)
        {
            PlayerProgress loadedPlayerProgress = new PlayerProgress();

            if (File.Exists(Application.persistentDataPath + "/" + saveFileName + slot.ToString() + saveFileExtension))
            {
                BinaryFormatter bf     = new BinaryFormatter();
                FileStream      stream = new FileStream(Application.persistentDataPath + "/" + saveFileName + slot.ToString() + saveFileExtension, FileMode.Open);

                loadedPlayerProgress = bf.Deserialize(stream) as PlayerProgress;

                stream.Close();
            }

            else
            {
                Debug.LogWarning("No save found !");
            }

            return(loadedPlayerProgress);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Unlock path depending the finished levels on the current world.
        /// O(n^2).
        /// </summary>
        /// <param name="playerProgress"></param>
        private void UnlockPaths(PlayerProgress playerProgress)
        {
            // Check all nodes of the world.
            foreach (GraphNode node in graph)
            {
                LevelNode ln = node as LevelNode;
                if (ln == null)
                {
                    continue;
                }

                LevelProgress levelProgress;
                // If found informations about the player progress on this level, try to unlock.
                if (playerProgress.worldProgress[ln.worldIndex].finishedLevels.TryGetValue(ln.levelIndex, out levelProgress))
                {
                    // If found and level finished,
                    if (!levelProgress.finished)
                    {
                        continue;
                    }

                    // Unlock all paths of this node.
                    foreach (GraphTransition t in ln.linkedNodes)
                    {
                        // Check if this path is an entrance.
                        if (t.exitIndex != -1)
                        {
                            // If not, check if this exit is unlocked.
                            if (!levelProgress.exits[t.exitIndex])
                            {
                                continue;
                            }
                        }

                        PathToSecret pathToSecret = t.path as PathToSecret;
                        if (pathToSecret == null)
                        {
                            if (!t.path.unlocked)
                            {
                                if (node.nodeIndex == playerProgress.currentNodeIndex)
                                {
                                    t.path.StartCoroutine(t.path.UnlockPath());
                                }

                                else
                                {
                                    t.path.DisplayPath();
                                }
                            }
                        }

                        else
                        {
                            // Retrieve data of the secret level node.
                            LevelNode secretLevelNode = graph.Find(x => x.nodeIndex == t.targetNodeindex) as LevelNode;

                            // Get sunflower seed collected and needed
                            int sfsCollected = playerProgress.worldProgress[ln.worldIndex].sunFlowerSeedCollected;
                            int sfsNeeded    = secretLevelNode.data.seedNeededToUnlock;

                            bool unlocked = sfsCollected >= sfsNeeded;

                            // Setup feedback only if necessary.
                            if (!unlocked)
                            {
                                pathToSecret.SetupUI(sfsCollected, sfsNeeded);
                            }

                            // Display it progessively
                            if (node.nodeIndex == playerProgress.currentNodeIndex)
                            {
                                pathToSecret.StartCoroutine(pathToSecret.UnlockSecretPath(unlocked));
                            }

                            // Display it directly
                            else
                            {
                                pathToSecret.DisplaySecretPath(unlocked);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        // Delegate method triggered when a new scene is loaded.
        private void NewSceneLoaded(Scene arg0, LoadSceneMode arg1)
        {
            // Reset time scale if game was paused.
            Time.timeScale = 1.0f;

            // Reset information about the loaded scene.
            isMainMenu = false;
            mainMenu   = null;

            isWorldMap = false;
            worldmap   = null;

            levelMgr = null;

            AudioClip musicToPlay = null;

            // Setup transition manager of the current scene.
            ui = GameObject.FindGameObjectWithTag("UI");
            if (ui)
            {
                transitionManager = ui.transform.Find("TransitionPanel").GetComponent <TransitionManager>();
            }

            // Load main menu :
            if (arg0.buildIndex == mainMenuIndex)
            {
                // Here we can create new game or load existing game, we can also change settings...
                isMainMenu = true;

                mainMenu    = GameObject.Find("MainMenuUI").GetComponent <MainMenuManager>();
                musicToPlay = audioMgr.mainMenuMusic;
            }

            // Load world map :
            else if (arg0.buildIndex == worldMapIndex)
            {
                // Here we can move on the world map and enter in a level or access to an another world.

                isWorldMap = true;

                if (playerProgress != null)
                {
                    currentWorldIndex = playerProgress.currentWorldIndex;
                }

                // for debug only.
                else
                {
                    // Load first save.
                    playerProgress    = SaveLoadManager.LoadPlayerProgress(saveSlotSelected);
                    currentWorldIndex = playerProgress.currentWorldIndex;
                }

                worldmap = GameObject.Find("WorldMap").GetComponent <WorldMapManager>();
                StartCoroutine(worldmap.SetupMap(playerProgress));

                musicToPlay = audioMgr.worldMapMusic;
            }

            // Load a level :
            else
            {
                // Try to get the level manager of this level.
                GameObject levelManager = GameObject.FindGameObjectWithTag("LevelManager");
                if (levelManager)
                {
                    levelMgr = levelManager.GetComponent <LevelManager>();
                    levelMgr.StartCoroutine(levelMgr.DisplayLevelIntro(arg0.name));

                    musicToPlay = levelMgr.data.levelMusic;
                }
            }

            if (audioMgr)
            {
                audioMgr.PlayMusic(musicToPlay);
            }
            else
            {
                Debug.LogWarning("No audio manager found in this level.");
            }
        }