Example #1
0
    public void SetGameState(GameVariables.GameState nextGameState)
    {
        Variables.CurrentGameState = nextGameState;
        switch (Variables.CurrentGameState)
        {
        case GameVariables.GameState.MainMenu:
            MainMenu.Show(true);
            break;

        case GameVariables.GameState.Start:
            Player.Respawn(false);
            AsteroidSpawnController.DestroyAllAsteroids();
            Variables.Score  = GameVariables.InitialScore;
            Variables.Health = GameVariables.InitialHealth;
            HealthHud.UpdateHealthHud();
            //Player.DestroyAll();
            BackgroundAudio.GetComponent <AudioSource>().Play();
            SetGameState(GameVariables.GameState.Playing);
            break;

        case GameVariables.GameState.Playing:
            Time.timeScale = 1;
            MainMenu.Show(false);
            BackgroundAudio.GetComponent <AudioLowPassFilter>().enabled = false;
            break;

        case GameVariables.GameState.Pause:
            Time.timeScale = 0;
            MainMenu.Show(true);
            BackgroundAudio.GetComponent <AudioLowPassFilter>().enabled         = true;
            BackgroundAudio.GetComponent <AudioLowPassFilter>().cutoffFrequency = 200;
            //MainMenuController.Show();
            break;

        case GameVariables.GameState.GameOver:
            BackgroundAudio.GetComponent <AudioSource>().Stop();
            //gameObject.SetActive(false);
            Time.timeScale = 0;
            MainMenu.Show(true);
            //MainMenuController.Show();
            break;

        default:
            break;
        }

        //Variables.CurrentGameState = nextGameState;
    }
Example #2
0
    private IEnumerator StartGameAnimation()
    {
        this.gameTime = GameVariables.gameTime;
        this.HudController.SetTimer(this.gameTime);
        Transform  CameraAxis      = this.CameraController.GetCameraAxis();
        Quaternion initialRotation = CameraAxis.localRotation;
        float      initialSize     = Camera.main.orthographicSize;

        for (float timer = 0; timer < 1;)
        {
            timer += Time.deltaTime;
            Camera.main.orthographicSize = Mathf.Lerp(initialSize, GameVariables.CameraInitialScale, timer);
            CameraAxis.localRotation     = Quaternion.Lerp(initialRotation, GameVariables.CameraInitialPosition, timer);
            yield return(new WaitForSeconds(Time.deltaTime));
        }
        gameState = GameVariables.GameState.Game;
    }
Example #3
0
    private void FixedUpdate()
    {
        switch (gameState)
        {
        case GameVariables.GameState.Menu:
            break;

        case GameVariables.GameState.Game:
            if (!this.Spawn.IsActive)
            {
                this.Spawn.IsActive = true;
            }
            this.actualPopulation += GameVariables.PopulationIncrem;
            for (int i = 0; i < disasterCount.Length; i++)
            {
                this.actualPopulation -= disasterCount[i] * GameVariables.DesastresMultp[i];
                Debug.Log($"Damage: " + disasterCount[i].ToString());
            }
            this.AudioController.SetNewTension(this.actualPopulation / this.maxPopulation);
            this.gameTime -= Time.deltaTime;
            this.HudController.SetTimer(this.gameTime);
            this.maxPopulation = Mathf.Max(this.actualPopulation, this.maxPopulation);
            HudController.SetPopulationScale(this.actualPopulation, this.maxPopulation);
            if (this.actualPopulation <= 0)
            {
                gameState = GameVariables.GameState.Lose;
            }
            break;

        case GameVariables.GameState.Lose:
            //Menu();
            if (!HudController.gameOver.activeSelf)
            {
                HudController.gameOver.SetActive(true);
            }
            Time.timeScale = 0;
            break;
        }
    }