Esempio n. 1
0
        // -----------------------------------------------------------------------------------
        private void DecreaseInstance(BonusItem item)
        {
            // decrease instance count
            item.awarded -= DecreaseInstance;
            item.timeout -= DecreaseInstance;
            activeInstanceCount--;

            foreach (InstanceTracker instance in instances.Values)
            {
                if (instance.active == item)
                {
                    instance.Clear();
                }
            }
        }
Esempio n. 2
0
        // -----------------------------------------------------------------------------------
        private void OnBonusAwarded(BonusItem item)
        {
            // Let's do the correct thing according to item type
            System.Type type = item.GetType();

            if (type == typeof(ExtraLifeItem))
            {
                livesLeft++;
                UI.instance.lives = livesLeft;
            }

            else if (type == typeof(SkillRechargeItem))
            {
                Skill.instance.FullRecharge();
            }

            else if (type == typeof(ExtraTimeItem))
            {
                Timer.instance.ExtendTimer((item as ExtraTimeItem).time);
            }

            else if (type == typeof(UnlockLetterItem))
            {
                UnlockLetterItem letterItem  = item as UnlockLetterItem;
                Data.UnlockState unlockState = Data.SaveFile.instance.unlockState;

                // already unlocked: award points
                if (unlockState[letterItem.letter])
                {
                    score += Config.instance.unlockLetterScore;
                    UI.instance.scoreDisplay.score = (long)score;
                }

                // unlock letters
                else
                {
                    UI.instance.unlockLetters.ShowLetter(letterItem.letter, true);
                    unlockState[letterItem.letter] = true;
                    Data.SaveFile.instance.Save();
                }
            }
        }
Esempio n. 3
0
        // -----------------------------------------------------------------------------------
        IEnumerator SpawnItems(bool isRetry)
        {
            while (playArea != null)
            {
                // check if we need to spawn new items
                foreach (BonusItem item in sourceItems)
                {
                    if (!CanSpawnCheck(item, isRetry))
                    {
                        continue;
                    }

                    // if it's paused, wait before spawning
                    while (Controller.instance.isPaused)
                    {
                        yield return(null);
                    }

                    // create instance
                    BonusItem copy = Instantiate(item, playArea.transform, true);
                    copy.awarded += bonusAwarded;
                    copy.awarded += DecreaseInstance;
                    copy.timeout += DecreaseInstance;
                    copy.Activate();

                    instances[item].Count(copy);
                    activeInstanceCount++;

                    // only spawn 1 item per loop
                    break;
                }

                // wait a bit between item spawning
                yield return(new WaitForSeconds(5));
            }
        }
Esempio n. 4
0
 public void Clear()
 {
     active = null;
 }
Esempio n. 5
0
 public void RoundReset()
 {
     round  = 0;
     active = null;
 }
Esempio n. 6
0
 public void Count(BonusItem item)
 {
     total++;
     round++;
     active = item;
 }
Esempio n. 7
0
        // -----------------------------------------------------------------------------------
        /// <summary>
        /// Returns true if the conditions for spawning that type of bonus item are met
        /// </summary>
        bool CanSpawnCheck(BonusItem item, bool isRetry)
        {
            // this item is not available on a retry round
            if (isRetry && !item.canSpawnOnRetryRound)
            {
                return(false);
            }

            // regardless of type, we can put so many items in the shadow.
            // The smaller the area, the less items we can put
            float clearedRatio = playArea.mask.clearedTotalRatio;

            // too little space
            if (clearedRatio > 0.9f)
            {
                return(false);
            }
            // a quarter space left
            else if (clearedRatio > 0.75f && activeInstanceCount >= 2)
            {
                return(false);
            }
            // half space left
            else if (clearedRatio > 0.50f && activeInstanceCount >= 3)
            {
                return(false);
            }
            // three quarters space left
            else if (clearedRatio > 0.25f && activeInstanceCount >= 4)
            {
                return(false);
            }
            // almost all covered
            else if (activeInstanceCount >= 5)
            {
                return(false);
            }

            // we can only have one of each item type instanced at the same time
            if (instances[item].active != null)
            {
                return(false);
            }

            // enforce per round limit
            if (instances[item].round == item.maxPerRound)
            {
                return(false);
            }

            // enforce per play limit
            if (instances[item].total == item.maxPerGame)
            {
                return(false);
            }

            // check the chance of spawning
            float chance = item.SpawnChance(playArea.mask.clearedRatio, round, totalRounds);

            if (Random.value > chance)
            {
                return(false);
            }

            return(true);
        }