Beispiel #1
0
    }     // RunLevel

    IEnumerator RunLevelCoroutine()
    {
        General.Logger.LogDetail("GameController", "RunLevelCoroutine", "Entering function.");
        int currentLevel = GLOBALS.currentLevel;

        if (levels.Length <= GLOBALS.currentLevel)
        {
            General.Logger.Log("GameController", "RunLevelCoroutine", "GLOBALS.currentLevel " + GLOBALS.currentLevel + " larger than levels.Length " + levels.Length + ". Exiting function.");
            yield break;
        }         // if

        sceneFadeInOut.sceneStarting = true;
        endTime     = Time.time + levels[GLOBALS.currentLevel].levelDurationInSeconds;
        playerDeath = false;
        General.Logger.Log("GameController", "RunLevelCoroutine", "Starting level " + currentLevel + " with endTime " + endTime + ".");
        if (levels[currentLevel].spawnPlayer)
        {
            General.Logger.Log("GameController", "RunLevelCoroutine", "Spawning player.");
            spawnedPlayer = Instantiate(player, levels[GLOBALS.currentLevel].spawnPlayerLocation, Quaternion.identity) as GameObject;
            dynamicallyAllocatedObjects.Add(spawnedPlayer);
            if (null == spawnedPlayer)
            {
                General.Logger.Log("GameController", "RunLevelCoroutine", "Spawning player failed.");
            }     // if
        }         // if
        General.Logger.Log("GameController", "RunLevelCoroutine", "Spawning beginningHazards. beginningHazards count is " + levels[currentLevel].beginningHazards.Length + ".");
        for (int loop = 0; loop < levels[currentLevel].beginningHazards.Length; loop++)
        {
            for (int loop2 = 0; loop2 < levels[currentLevel].beginningHazards[loop].spawnSize; loop2++)
            {
                Vector3    spawnPosition   = levels[currentLevel].beginningHazards[loop].hazardPosition;
                Vector3    spawnRotation   = levels[currentLevel].beginningHazards[loop].hazardRotation;
                Quaternion spawnQuaternion = Quaternion.Euler(spawnRotation.x, spawnRotation.y, spawnRotation.z);
                GameObject hazard          = Instantiate(levels[currentLevel].beginningHazards[loop].hazardObject, spawnPosition, spawnQuaternion) as GameObject;

                hazard.transform.localScale = levels[currentLevel].beginningHazards[loop].hazardScale;
                dynamicallyAllocatedObjects.Add(hazard);
            }     // for
        }         // for
        if (null != levels[currentLevel].music)
        {
            General.Logger.Log("GameController", "RunLevelCoroutine", "Playing music.");
            levels[currentLevel].music.enabled = true;
            levels[currentLevel].music.Play();
        }         // if
        if (null != levels[currentLevel].openingImage)
        {
            General.Logger.Log("GameController", "RunLevelCoroutine", "Displaying opening image.");
            levels[currentLevel].openingImage.enabled = true;
            yield return(new WaitForSeconds(levels[currentLevel].openingImageDurationInSeconds));

            General.Logger.Log("GameController", "RunLevelCoroutine", "Hiding opening image.");
            levels[currentLevel].openingImage.enabled = false;
        }         // if
        guiManager.UpdateScore();
        guiManager.UpdateLives(GetSpawnedPlayer());
        guiManager.UpdateHealth(GetSpawnedPlayer());

        while (!DidLevelAutoEnd(currentLevel))
        {
            int spawnIndex = 0;

            guiManager.UpdateScore();
            guiManager.UpdateLives(GetSpawnedPlayer());
            guiManager.UpdateHealth(GetSpawnedPlayer());
            while (true)
            {
                bool didSpawn = false;

                for (int loop = 0; loop < levels[currentLevel].spawnedHazards.Length; loop++)
                {
                    if (spawnIndex < levels[currentLevel].spawnedHazards[loop].spawnSize)
                    {
                        Vector3    spawnPosition   = levels[currentLevel].spawnedHazards[loop].hazardPosition;
                        Vector3    spawnRotation   = levels[currentLevel].spawnedHazards[loop].hazardRotation;
                        Quaternion spawnQuaternion = Quaternion.Euler(spawnRotation.x, spawnRotation.y, spawnRotation.z);
                        GameObject hazard          = Instantiate(levels[currentLevel].spawnedHazards[loop].hazardObject, spawnPosition, spawnQuaternion) as GameObject;

                        hazard.transform.localScale = levels[currentLevel].spawnedHazards[loop].hazardScale;
                        dynamicallyAllocatedObjects.Add(hazard);
                        didSpawn = true;
                        yield return(new WaitForSeconds(0.5f));
                    }             // if
                }                 // for
                if (!didSpawn)
                {
                    break; // while
                }          // if
                spawnIndex++;
            }              // while
            yield return(new WaitForSeconds(levels[currentLevel].spawnWait));
        }                  // while

        sceneFadeInOut.sceneStarting = false;
        if (0 <= levels[currentLevel].endLevelWait)
        {
            General.Logger.Log("GameController", "RunLevelCoroutine", "End level wait: " + levels[currentLevel].endLevelWait + ".");
            yield return(new WaitForSeconds(levels[currentLevel].endLevelWait));
        }         // if
        if (null != levels[currentLevel].music)
        {
            General.Logger.Log("GameController", "RunLevelCoroutine", "Stopping music.");
            levels[currentLevel].music.Stop();
        }         // if
        General.Logger.Log("GameController", "RunLevelCoroutine", "Destroying dynamic objects.");
        DestroyDynamicObjects();

        if (LevelChaining.EndGame != levels[currentLevel].levelChaining)
        {
            if ((LevelChaining.LoadNextLevel == levels[currentLevel].levelChaining) &&
                (!playerDeath))
            {
                GLOBALS.currentLevel++;
                General.Logger.Log("GameController", "RunLevelCoroutine", "Incrimented level number to " + GLOBALS.currentLevel + ".");
            }             // if
            if (playerDeath)
            {
                levels[GLOBALS.currentLevel].levelChaining = LevelChaining.LoadNextLevel;
                playerDeath = false;
                General.Logger.Log("GameController", "RunLevelCoroutine", "Level chaining and playerDeath reset to LevelChaining.LoadNextLevel after processing player death.");
            }             // if
            if (LevelChaining.LastLevel != levels[currentLevel].levelChaining)
            {
                General.Logger.Log("GameController", "RunLevelCoroutine", "Loading level number " + GLOBALS.currentLevel + ".");
                RunLevel();
            }             // if
            else if (LevelChaining.LastLevel == levels[currentLevel].levelChaining)
            {
                General.Logger.Log("GameController", "RunLevelCoroutine", "Calling GameOver().");
                GameOver();
            }     // else if
        }         // if
        else
        {
            guiManager.ActivateRestart();
        }         // else

        General.Logger.LogDetail("GameController", "RunLevelCoroutine", "Ending level " + currentLevel);
    }     // RunLevelCoroutine