Exemplo n.º 1
0
    // ---------- SPAWNS ----------------------------------------------------+

    #region SPAWN ANYTHING
    private void SpawnAnything()
    {
        if (Time.time - previousSpawnTime > spawnGap_CurrentWave)
        {
            // ----- SPAWN BOSS -----

            if (state == ObstacleStates.BOSS_NEAR)
            {
                // Fire event: Boss is ready to spawn
                BossIsReadyToSpawn?.Invoke();

                // Set state as "boss entering"
                state = ObstacleStates.BOSS_ENTERING;
            }

            // ----- SPAWN OBSTACLE -----

            if ((state == ObstacleStates.SPAWNING) || (state == ObstacleStates.BOSS_FIRING) ||
                (state == ObstacleStates.BOSS_FIRING_JAMMED_GUN))
            {
                // Spawn obstacle
                SpawnObstacleFromPool();

                //Debug.Log(Time.time);

                // Set previous spawn time
                previousSpawnTime = Time.time;

                // Fire projectile was spawned event, only if the boss is on screen
                //if (state == ObstacleStates.BOSS_FIRING)
                if ((state == ObstacleStates.BOSS_FIRING) || (state == ObstacleStates.BOSS_FIRING_JAMMED_GUN))
                {
                    // Get boss firing position
                    float firingPosition = obstacleGroupSelector.GetBossFiringPositionY();

                    // Fire event: Projectile was spawned
                    ProjectileWasSpawned?.Invoke(firingPosition);
                }

                // Increment dificulty
                IncrementDifficulty();
            }
        }
    }
Exemplo n.º 2
0
    // ---------- INITIALIZATIONS ----------------------------------------------------+

    #region INITIALIZE
    public void Initialize(float _spawnAndExit_AbsolutePositionX, float _minionsSpawnPositionY,
                           float _obstacleSpeed, Vector2 _deathDragForce)
    {
        // Initialize state
        state = ObstacleStates.SERENITY;

        // Initialize random
        int seed = (int)System.DateTime.Now.Ticks & 0x0000FFFF;

        rnd = new System.Random(seed);

        // Note: obstacle's deathDragForce is half of the one for the map

        // Initialize projectilesParent
        obstaclesParent      = new GameObject();
        obstaclesParent.name = "Obstacles";

        // Initialize obstacles
        InitializeObstacles(_spawnAndExit_AbsolutePositionX, _minionsSpawnPositionY, _obstacleSpeed, _deathDragForce);

        // Initialize projectile walls
        InitializeProjectileWalls();
    }
Exemplo n.º 3
0
    /*
     #region SET STATE AS BOSS NEAR
     * public void SetStateAs_BossNear()
     * {
     *  // Set state
     *  state = ObstacleStates.BOSS_NEAR;
     * }
     #endregion
     */

    #region SET STATE AS BOSS FIRING
    public void SetStateAs_BossFiring()
    {
        // Set state
        state = ObstacleStates.BOSS_FIRING;
    }
Exemplo n.º 4
0
 public void StartSpawningState()
 {
     // Set state
     state = ObstacleStates.SPAWNING;
 }
Exemplo n.º 5
0
    // ---------- STATES ----------------------------------------------------+

    #region SET STATE AS SERENITY
    public void SetStateAs_Serenity()
    {
        // Set state
        state = ObstacleStates.SERENITY;
    }
Exemplo n.º 6
0
    // ---------- INCREMENT DIFFICULTY ----------------------------------------------------+

    #region INCREMENT DIFFICULTY
    private void IncrementDifficulty()
    {
        if ((state == ObstacleStates.SPAWNING) || (state == ObstacleStates.BOSS_FIRING))
        {
            // Increase total spawned obstacles
            spawnedObstacles_Total++;

            // Increase spawned obstacles on current wave
            spawnedObstacles_CurrentWave++;

            // Local flag
            bool waveChanged = false;

            // ----- IF MINIMUM "SPAWN GAP" WAS REACHED -----

            if (minimumSpawnGap_WasReached)
            {
                //
                if ((state == ObstacleStates.SPAWNING) &&
                    (spawnedObstacles_CurrentWave >= totalObstacles_PerBossGap_CurrentWave))
                {
                    //
                    waveChanged = true;

                    // Increase wave
                    currentWave++;

                    // Reset spawned obstacles
                    spawnedObstacles_CurrentWave = 0;

                    // If shots per boss can increase
                    if (totalShotsPerBoss_CurrentWave < maxShotsPerBoss)
                    {
                        // Set total shots for current wave
                        totalShotsPerBoss_CurrentWave =
                            totalShotsPerBoss_CurrentWave + increaseConstant_ShotsPerBoss;

                        //Debug.Log("W: " + (currentWave + 1) + ". O: " + totalShotsPerBoss_CurrentWave);
                    }
                }

                //
                else if ((state == ObstacleStates.BOSS_FIRING) &&
                         (spawnedObstacles_CurrentWave >= totalShotsPerBoss_CurrentWave))
                {
                    //
                    waveChanged = true;

                    // Increase wave
                    currentWave++;

                    // Reset spawned obstacles
                    spawnedObstacles_CurrentWave = 0;

                    // If "obstacles per boss gap" can increase
                    if (totalObstacles_PerBossGap_CurrentWave < maxObstaclesPerBossGap)
                    {
                        // Set total obstacles for current wave
                        totalObstacles_PerBossGap_CurrentWave =
                            totalObstacles_PerBossGap_CurrentWave + increaseConstant_ObstaclesPerBossGap;

                        //Debug.Log("W: " + (currentWave + 1) + ". O: " + totalObstacles_PerBossGap_CurrentWave);
                    }
                }
            }

            // ----- IF MINIMUM "SPAWN GAP" WAS NOT REACHED -----

            else
            {
                if (spawnedObstacles_CurrentWave >= totalObstacles_CurrentWave)
                {
                    //
                    waveChanged = true;

                    // ----- INCREASE WAVE -----

                    // Increase wave
                    currentWave++;

                    // Reset spawned obstacles
                    spawnedObstacles_CurrentWave = 0;

                    // ----- IF MINIMUM "SPAWN GAP" WAS REACHED -----

                    if (currentWave >= obstaclesPerWave.Length)
                    {
                        // If next state is "spawning"
                        if (state == ObstacleStates.BOSS_FIRING)
                        {
                            // Set obstacles current wave (+increment)
                            totalObstacles_PerBossGap_CurrentWave =
                                obstaclesPerWave[currentWave - 2] + increaseConstant_ObstaclesPerBossGap;

                            // Set obstacles current wave
                            totalShotsPerBoss_CurrentWave = obstaclesPerWave[currentWave - 1];

                            Debug.Log("W: " + (currentWave + 1) + ". O: " + totalObstacles_PerBossGap_CurrentWave);
                        }

                        // If next state is "boss entering"
                        else if (state == ObstacleStates.SPAWNING)
                        {
                            // Set obstacles current wave (+increment)
                            totalShotsPerBoss_CurrentWave =
                                obstaclesPerWave[currentWave - 2] + increaseConstant_ShotsPerBoss;

                            // Set obstacles current wave
                            totalObstacles_PerBossGap_CurrentWave = obstaclesPerWave[currentWave - 1];

                            Debug.Log("W: " + (currentWave + 1) + ". O: " + totalShotsPerBoss_CurrentWave);
                        }

                        // Set flag
                        minimumSpawnGap_WasReached = true;
                    }

                    // ----- IF MINIMUM "SPAWN GAP" WAS NOT REACHED -----

                    else
                    {
                        //Debug.Log(totalObstacles_CurrentWave + ", " + currentWave + ", " + obstaclesPerWave.Length);

                        // Set obstacles current wave
                        totalObstacles_CurrentWave = obstaclesPerWave[currentWave];

                        // Set current spawn gap
                        spawnGap_CurrentWave = spawnGapsPerWave[currentWave];

                        //Debug.Log("W: " + (currentWave + 1 ) + ". O: " + totalObstacles_CurrentWave);

                        // Update debug variable
                        currentSpawnCooldown_Text.text = "Spawn Cooldown: " + spawnGap_CurrentWave.ToString("F2");
                    }
                }
            }

            // ----- CHANGE STATE -----

            if (waveChanged)
            {
                // If spawning, change state to boss near
                if (state == ObstacleStates.SPAWNING)
                {
                    state = ObstacleStates.BOSS_NEAR;
                }

                // If boss firing, change jammed gun
                else if (state == ObstacleStates.BOSS_FIRING)
                {
                    // Set state as "boss firing jammed gun"
                    state = ObstacleStates.BOSS_FIRING_JAMMED_GUN;
                }

                // Fire event: Current wave has changed
                CurrentWave_HasChanged?.Invoke(currentWave + 1);
            }
        }

        else if (state == ObstacleStates.BOSS_FIRING_JAMMED_GUN)
        {
            // ----- CHANGE STATE -----

            // Set state as "boss vulnerable"
            state = ObstacleStates.BOSS_VULNERABLE;

            // Fire event: Boss is vulnerable
            BossIsVulnerable?.Invoke();
        }
    }