Ejemplo n.º 1
0
    // Reloads the game
    public void RestartGame()
    {
        // Log restart action
        logger.addTimesRestarted();

        // Ensure time running
        Time.timeScale = 1f;

        if (!GM.isGameOver())
        {
            logger.resetDumped();
            logger.StatDump();
        }
        logger.resetDumped();
        logger.resetStats();

        // Load same scene
        SceneManager.LoadScene(0);
    }
Ejemplo n.º 2
0
    void FixedUpdate()
    {
        zombieNumber.text = "Zs LEFT: " + zLeft;

        // If game is not over and wave not in progress
        if (!gameOver && !inWave && wave < maxWaves)
        {
            // Inc Wave number
            wave++;

            // Adjust possible enemies, dependant on wave number
            ManageEnemyList();

            waveNumber.text = "WAVE: " + wave;

            // Calculate waveDR
            if (waveDRConstant < 0)
            {
                waveDRConstant = 1;
            }

            waveDR = waveDRConstant * wave + 5 * skill;


            // Build composition of wave
            loadWaveComposition();

            // Count number of Z that should be spawned
            toSpawn = waveComp.Count;
            spawned = 0;

            // Wave in progress
            inWave = true;

            // Spawn Z every spawnRate seconds.
            // Number of Zs spawning at once proportional to wave number. Higher wave == more Z spawn at once == More difficult
            for (int i = 0; i < wave; i++)
            {
                StartCoroutine(spawnZ());
            }
        }

        if (spawned == toSpawn) // If all Z spawned
        {
            // Stop trying to spawn
            StopAllCoroutines();
        }


        if (zLeft <= 0) // If all Z dead
        {
            //Wave no longer in progress
            inWave = false;

            // Spawn Health
            SpawnHealth();


            // If final wave
            if (wave + 1 > maxWaves)
            {
                // Game Won
                win = true;
            }
        }


        if (win)
        {
            // Game is over (Win), display win menu
            // Should only rin when player not killed and won game

            gameOver = true;

            // Display win menu
            winMenu.SetActive(true);
            winMenu.GetComponent <Animator>().SetTrigger("GameOver");

            // Log game win
            logger.addGamesWon();

            logger.StatDump();

            // Reset cursor to default
            GetComponent <SetCursor>().ResetCursor();
        }
        else if (gameOver)
        {
            // Game is over (Defeat), Display game over menu
            // Should only run when player killed

            // Stop more Zs spawning
            StopAllCoroutines();

            // Log enemy that killed player
            logger.SetKilledPlayer(lastEnemyToAttack);

            // Log wave reached
            logger.addWaveReached(wave);
            // Print log to output
            logger.StatDump();

            // Display game over menu
            gameOverMenu.SetActive(true);
            gameOverMenu.GetComponent <Animator>().SetTrigger("GameOver");

            // Reset cursor to default
            GetComponent <SetCursor>().ResetCursor();
        }
    }