Example #1
0
        // -----------------------------------------------------------------------------------
        /// <summary>
        /// Call to get the bonus items associated with the new play area and initialize
        /// the new round
        /// Some bonus items won't spawn on a retry play, so we need to know if it's a retry
        /// round or not
        /// </summary>
        public void InitializeRound(PlayArea playArea, int round, bool isRetry)
        {
            this.playArea       = playArea;
            this.round          = round;
            activeInstanceCount = 0;

            // initialize the counters
            if (round == 0)
            {
                instances = new Dictionary <BonusItem, InstanceTracker>();
                foreach (BonusItem item in sourceItems)
                {
                    instances.Add(item, new InstanceTracker());
                }
            }
            else
            {
                foreach (BonusItem item in sourceItems)
                {
                    instances[item].RoundReset();
                }
            }

            StartCoroutine(SpawnItems(isRetry));
        }
Example #2
0
 // -----------------------------------------------------------------------------------
 public void StartTracking(PlayArea playArea)
 {
     this.playArea = playArea;
     tracking      = true;
     lastWidth     = -1;
     lastHeight    = -1;
 }
Example #3
0
 // -----------------------------------------------------------------------------------
 /// <summary>
 /// Call after the round ends to clean up remaining items
 /// </summary>
 public void EndRound()
 {
     foreach (InstanceTracker instance in instances.Values)
     {
         if (instance.active != null)
         {
             Destroy(instance.active.gameObject);
         }
     }
     playArea = null;
     StopAllCoroutines();
 }
Example #4
0
        // --- Methods ----------------------------------------------------------------------------------
        // -----------------------------------------------------------------------------------
        IEnumerator InitializeRound(bool isRetry)
        {
            Debug.Log("Starting round: " + (round + 1));

            // destroy previous area
            if (playArea != null)
            {
                Destroy(playArea.gameObject);
            }

            // Play a random track
            SoundManager.instance.PlayRandomRoundClip();

            // save to restore later
            roundStartLives = livesLeft;

            // Load the images
            CharacterFile.RoundImages roundData = sourceFile.LoadRound(round);

            // create a fresh play area
            System.Type bossType = roundBoss[round].GetType();
            //bossType = typeof(Slimy);
            playArea = Instantiate(sourcePlayArea, sourcePlayArea.transform.parent, true);
            playArea.gameObject.SetActive(true);
            playArea.Setup(roundData.baseImage, roundData.shadowImage, bossType);
            Debug.Log("Boss: " + bossType.Name.ToString());

            // reset percentage tracker to zero
            lastPercentage = 0;

            // reset score
            score = 0;

            // check when the player spawns to count lives / game overs
            playArea.player.spawned += OnPlayerSpawned;
            playArea.player.died    += OnPlayerDied;

            // Let the camera know it can start tracking the player
            cameraController.StartTracking(playArea);

            // reset the UI
            UI.instance.Reset(
                livesLeft,
                Config.instance.clearPercentage,
                Config.instance.roundTime,
                Skill.instance.maxTime,
                Skill.instance.remainingTime);

            // reset the timer
            Timer.instance.ResetTimer(Config.instance.roundTime);

            // Hide the player
            playArea.player.Hide();

            // Hide the transition
#if UNITY_EDITOR
            if (Transition.instance != null)
            {
                yield return(StartCoroutine(Transition.instance.Hide()));
            }
#else
            yield return(StartCoroutine(Transition.instance.Hide()));
#endif
            // play the intro animation for the round
            yield return(StartCoroutine(UI.instance.roundStart.Show(round, SoundManager.instance.currentBGM)));

            // Create a square that randomly changes sizes
            // until the fire button gets pressed
            const float Area       = 50 * 50;
            const int   MaxWidth   = 100;
            const int   MinWidth   = 20;
            const float FlickDelay = 0.075f;
            initialSquare.gameObject.SetActive(true);
            initialSquare.mesh.triangles = new int[]
            {
                0, 1, 2,
                3, 0, 2
            };
            float w = 0, h = 0;
            while (true)
            {
                w  = Random.Range(MinWidth, MaxWidth);
                h  = Area / w;
                w /= 2;
                h /= 2;
                Vector3[] corners = new Vector3[]
                {
                    new Vector3(-w, -h),
                    new Vector3(-w, h),
                    new Vector3(w, h),
                    new Vector3(w, -h),
                };

                initialSquare.mesh.vertices = corners;

                // wait until the next random square
                // or cancel wait if user presses button
                float wait = FlickDelay;
                while (wait >= 0 && !Input.GetButtonDown("Cut"))
                {
                    wait -= Time.deltaTime;
                    yield return(null);
                }
                if (wait > 0)
                {
                    break;
                }
            }

            // hide the round start UI
            UI.instance.roundStart.Hide();

            IntRect rect = new IntRect()
            {
                x      = playArea.player.x - Mathf.FloorToInt(w),
                y      = playArea.player.y - Mathf.FloorToInt(h),
                width  = Mathf.RoundToInt(w * 2),
                height = Mathf.RoundToInt(h * 2)
            };

            // re-enable the player and put it in a corner of the square
            playArea.player.Spawn(rect.x, rect.y);

            // set callbacks to check game progress
            playArea.mask.maskCleared += OnMaskCleared;

            // create the square and destroy the "preview"
            playArea.CreateStartingZone(rect);
            initialSquare.gameObject.SetActive(false);

            // now that the play area has colliders,
            // place the boss safely in the shadow
            playArea.boss.gameObject.SetActive(true);
            playArea.boss.PlaceRandomly();
            playArea.boss.minionKilled += OnMinionKilled;
            playArea.boss.Run();

            // Let the bonus manager know a new round started
            BonusItemManager.instance.InitializeRound(playArea, round, isRetry);

            // start tracking it
            UI.instance.bossTracker.StartTracking(playArea.boss);

            // start timer
            Timer.instance.StartTimer();

            // Handle the pause from here on out
            StartCoroutine("PauseHandler");

            yield break;
        }