示例#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>
        /// Update the level preview and informations about the level.
        /// </summary>
        /// <param name="nodeName">Node information.</param>
        /// <param name="levelData">Data of this level. null if the node is not a level.</param>
        /// <param name="levelProgress">Current progress of the player in this level. null if no progress.</param>
        public void UpdateLevelPreview(string nodeName, LevelData levelData, LevelProgress levelProgress)
        {
            // Update what is this node.
            this.nodeName.text = nodeName;

            bool levelInfoDisplayed = false;

            // Display level infos.
            if (levelData != null)
            {
                // Update level infos.
                nodeName2.text     = levelData.levelName;
                nodeName2.fontSize = (levelData.levelName.Length > 18) ? 45 : 55;

                int featherCollected = 0;
                // Try to get progress.
                if (levelProgress != null)
                {
                    featherCollected = levelProgress.feathersCollected;
                }

                // Update feathers infos.
                feathers.text = featherCollected + " / " + levelData.totalFeathers;

                // Special item info.
                int i = 0;
                foreach (Transform child in specialItemParent.transform)
                {
                    // Display or hide depending if the item is present in the level.
                    child.gameObject.SetActive(levelData.itemsPresent[i]);

                    // Check if the special item is present on the level.
                    if (levelData.itemsPresent[i])
                    {
                        Image img = child.gameObject.GetComponent <Image>();

                        // Save exist
                        if (levelProgress != null)
                        {
                            // Item found, highlight it.
                            if (levelProgress.specialItemsFound[i])
                            {
                                img.color = Color.white;

                                if (i == 0 && levelProgress.treasureFound)
                                {
                                    img.sprite = levelData.treasureToFound.sprite;
                                }
                            }

                            // Item not found, remove highlight.
                            else
                            {
                                img.color = notFoundColor;
                            }
                        }

                        // No save. No highlight.
                        else
                        {
                            img.color = notFoundColor;
                        }
                    }

                    i++;
                }

                levelInfoDisplayed = true;
            }

            DisplayLevelInfos(levelInfoDisplayed);
        }
示例#3
0
        /// <summary>
        /// Store the current level progress and save it.
        /// </summary>
        /// <param name="feathersCollected"></param>
        /// <param name="itemsFound"></param>
        public void SaveLevelProgress(int feathersCollected, bool[] itemsFound, bool treasureFound)
        {
            // Debug.
            if (playerProgress == null)
            {
                return;
            }

            LevelProgress levelProgress = null;

            // Save found. Update for the best values.
            if (playerProgress.worldProgress[currentWorldIndex].finishedLevels.TryGetValue(currentLevelIndex, out levelProgress))
            {
                levelProgress.feathersCollected = Mathf.Max(feathersCollected, levelProgress.feathersCollected);
            }

            // level finished for the first time, create and add new entry with the corect amount of exits and feathers collected.
            else
            {
                levelProgress = new LevelProgress(levelMgr.data.exitCount, feathersCollected);

                playerProgress.worldProgress[currentWorldIndex].finishedLevels.Add(currentLevelIndex, levelProgress);
            }

            // Update items :
            for (int i = 0; i < levelProgress.specialItemsFound.Length; i++)
            {
                // Don't update item if already found.
                if (levelProgress.specialItemsFound[i])
                {
                    continue;
                }

                // Update if item has been found.
                if (itemsFound[i])
                {
                    levelProgress.specialItemsFound[i] = true;

                    // Sunflower seed obtained.
                    if (i == 3)
                    {
                        playerProgress.worldProgress[currentWorldIndex].sunFlowerSeedCollected++;
                    }
                }
            }

            // Update treasure if exist and hasn't already save.
            if (treasureFound && !levelProgress.treasureFound)
            {
                levelProgress.treasureFound = treasureFound;
                playerProgress.treasuresFound.Add(currentWorldIndex + "-" + currentLevelIndex, true);
            }

            // Update exit taken.
            levelProgress.exits[levelMgr.ExitTaken] = true;

            // Cumulate stats.
            playerProgress.deathCount += levelMgr.DeathCount;
            playerProgress.timePlayed += levelMgr.Timer;

            // TODO save best time on a specific level.

            // Save.
            SaveLoadManager.SavePlayerProgress(playerProgress, saveSlotSelected);
        }