Example #1
0
        // -----------------------------------------------------------------------------------
        /// <summary>
        /// Saves game results into the save file
        /// </summary>
        private void SaveResults(out bool isBestTime, out bool isHighScore)
        {
            Data.CharacterStats stats     = Data.SaveFile.instance.GetCharacterStats(sourceFile.guid);
            Data.RoundData      roundData = stats.rounds[round];
            Data.Records        records   = roundData.records[Config.instance.difficulty];

            // only set as cleared if not on easy AND round is one less than the last one
            if (!roundData.cleared)
            {
                bool isHardOnlyRound   = round == Config.Rounds - 1;
                Config.Difficulty diff = Config.instance.difficulty;
                roundData.cleared = diff == Config.Difficulty.Hard ||
                                    (diff == Config.Difficulty.Normal && !isHardOnlyRound);
            }

            float elapsed = Timer.instance.elapsedTime;

            isBestTime = records.bestTime == -1 || elapsed < records.bestTime;
            if (isBestTime)
            {
                records.bestTime = elapsed;
            }

            long scoreL = (long)score;

            isHighScore = scoreL > records.highScore;
            if (isHighScore)
            {
                records.highScore = scoreL;
            }

            Data.SaveFile.instance.Save();
        }
Example #2
0
        // --- MonoBehaviour ----------------------------------------------------------------------------
        // -----------------------------------------------------------------------------------
        void Start()
        {
#if UNITY_EDITOR
            if (sourceFile == null)
            {
                sourceFile = new CharacterFile.File(DEBUG_file);
            }
#endif
            if (SoundManager.instance == null)
            {
                Instantiate(Resources.Load("Sound Manager"));
            }

            cameraController = Camera.main.GetComponent <CameraController>();
            sourcePlayArea.gameObject.SetActive(false);

            // character is now set as played
            Data.SaveFile       saveFile = Data.SaveFile.instance;
            Data.CharacterStats stats    = saveFile.GetCharacterStats(sourceFile.guid);
            if (!stats.played)
            {
                stats.played = true;
                saveFile.Save();
            }

            // randomize bosses (we have 3, but need 4)
            roundBoss = new List <Enemy>(sourcePlayArea.GetBosses());
            roundBoss.Shuffle();
            roundBoss.Add(roundBoss[Random.Range(0, roundBoss.Count)]);

            // basic initialization
            round     = 0;
            livesLeft = Config.instance.startLives;
            Skill.instance.Initialize();
            Timer.instance.timedOut += OnTimerTimedOut;
            BonusItemManager.instance.InitializeGame(sourceFile.availableRounds);

            // Bonus manager event handling
            BonusItemManager.instance.bonusAwarded += OnBonusAwarded;

            // start the first round
            StartCoroutine(InitializeRound(false));
        }
Example #3
0
        // -----------------------------------------------------------------------------------
        int SortFunc_ByUnplayed(CharacterIcon a, CharacterIcon b)
        {
            Data.CharacterStats stats_a = Data.SaveFile.instance.GetCharacterStats(a.characterFile.guid);
            Data.CharacterStats stats_b = Data.SaveFile.instance.GetCharacterStats(b.characterFile.guid);

            // if both are either played, or unplayed; sort by creation date
            if (stats_a.played == stats_b.played)
            {
                return(SortFunc_ByDateCreated(a, b));
            }

            // else, unplayed comes first
            if (!stats_a.played)
            {
                return(1);
            }
            else
            {
                return(-1);
            }
        }
Example #4
0
        // -----------------------------------------------------------------------------------
        public void SetCharacter(CharacterFile.File characterFile)
        {
            bool saveNeeded = false;

            stats = Data.SaveFile.instance.GetCharacterStats(characterFile.guid);
            this.characterFile = characterFile;
            for (int i = 0; i < Config.Rounds; i++)
            {
                if (stats.rounds[i].cleared)
                {
                    // only play the animation the first time you unlock an image
                    if (stats.rounds[i].lockAnimationPlayed)
                    {
                        icons[i].SetUnlocked(characterFile.baseSheet.roundIcons[i]);
                    }
                    else
                    {
                        icons[i].AnimateUnlock(characterFile.baseSheet.roundIcons[i]);
                        stats.rounds[i].lockAnimationPlayed = true;
                        saveNeeded = true;
                    }
                }
                else if (i < characterFile.availableRounds)
                {
                    icons[i].SetLocked();
                }
                else
                {
                    icons[i].SetUnlocked(unavailableSprite);
                }
            }

            if (saveNeeded)
            {
                Data.SaveFile.instance.Save();
            }
        }