예제 #1
0
    // ---------- PUBLIC METHODS ----------------------------------------------------+

    #region START OR CONTINUE GAME
    // Continue the game if it was paused, start new game otherwise
    public void StartOrContinueGame()
    {
        // If game was over
        if (gameState == GameStates.GAME_OVER)
        {
            // Clear active obstacles from previous match
            obstacleManager.ClearObstacles();

            // Set serenity state
            mapManager.SetSerenityState();
        }

        // If new match
        if (gameState == GameStates.TITLE_SCREEN ||
            gameState == GameStates.GAME_OVER)
        {
            // Reset match UI
            CurrentScore_HasChanged?.Invoke(0);
            CurrentWave_HasChanged?.Invoke(1);

            // Spawn new hero
            heroManager.SpawnNewHero();

            // Reset obstacles
            obstacleManager.ResetValuesForNewGame();

            // Reset bosses
            bossManager.ResetValuesForNewGame();

            // Start moving map.
            mapManager.StartHeroEnteringState();

            // Reset dodged obstacles
            currentScore = 0;
        }

        // Fire event: Game started or continued
        GameStartedOrContinued?.Invoke(gameState != GameStates.PAUSED);

        // Set game as running or intro
        //gameState = GameStates.INTRO;
        gameState = GameStates.RUNNING;

        // Unpause game
        Time.timeScale = 1.0f; // 1
    }
예제 #2
0
    // ---------- RESPOND TO [WAVE RELATED] EVENTS ----------------------------------------------------+

    #region RESPOND TO "CURRENT WAVE HAS CHANGED" EVENT
    private void RespondTo_CurrentWave_HasChanged_Event(int _wave)
    {
        // Fire event: Current wave has changed
        CurrentWave_HasChanged?.Invoke(_wave);
    }
예제 #3
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();
        }
    }