示例#1
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);
        }
示例#2
0
        /// <summary>
        /// Return the number of sun flower seeds required to unlock the secret level.
        /// </summary>
        /// <returns></returns>
        public int CountSunflowerSeedNeeded()
        {
            int sunflowerSeedNeeded = 0;

            GameObject[] nodes = GameObject.FindGameObjectsWithTag("Node");

            foreach (GameObject gn in nodes)
            {
                LevelNode ln = gn.GetComponent <LevelNode>();

                if (ln)
                {
                    // Don't count secret level seed.
                    if (ln.data.isSecretLevel)
                    {
                        continue;
                    }

                    // if sunflower seed is present in this level, increment the counter.
                    if (ln.data.itemsPresent[3])
                    {
                        sunflowerSeedNeeded++;
                    }
                }
            }

            return(sunflowerSeedNeeded);
        }
示例#3
0
        /// <summary>
        /// Get level index associated to the node index.
        /// </summary>
        /// <param name="nodeIndex"></param>
        /// <returns></returns>
        public int GetLevelIndex(int nodeIndex)
        {
            int levelIndex = -1;

            GraphNode node = graph.Find(x => x.nodeIndex == nodeIndex);
            LevelNode ln   = node as LevelNode;

            if (ln)
            {
                levelIndex = ln.levelIndex;
            }

            return(levelIndex);
        }
示例#4
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));
            }
        }
示例#5
0
 private void SwitchToNewLevel(LevelNode node)
 {
     GameManager.instance.LoadNewLevel(node.worldIndex, node.levelIndex);
 }
示例#6
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);
                            }
                        }
                    }
                }
            }
        }