Beispiel #1
0
    public override AbstractState UpdateState()
    {
        // anchor: ran out of Time in this state
        if (RemainingTimeInState >= SecondsToStateChange)
        {
            // return next AbstractState -> State_MainDecay
            return(NextState);
        }
        else
        {
            //Debug.Log("LevelBalancing: " + LevelBalancing.GetBalanceVariance()+"\nLastBalanceInState: "+ LastBalanceInState());
            if (!SpawnTrashOverTime() &&                                                        // If the normal SpawnOverTime logic takes place, skip this step
                (LastBalanceInState() >= timeBetweenBalancing || lastbaBalanceUpdate < 0f))     // Check if enough time has elapsed since last Balance spawn. Or its the first Balance spawn
            {
                Debug.Log("Balancing is triggered");
                if (LevelBalancing.GetBalanceVariance() < 0f)     // Check if there is need for Balance | Look up description in LevelBalancing Class for more info

                {
                    GameInfo.TrashSpawner.SpawnOnTimer();
                }
                else if (LevelBalancing.GetBalanceVariance() > Trees.startingNatureValue / 2f)
                {
                    Debug.Log("Balancing is executing.");
                    GameInfo.PlantDestroyer.DestroyRandomTreeInMiddleState();
                }
                lastbaBalanceUpdate = GameInfo.SpentSecondsIngame;
            }
        }
        return(this);
    }
    public override AbstractState UpdateState()
    {
        // anchor: ran out of Time in this state
        if (RemainingTimeInState >= SecondsToStateChange)
        {
            return(NextState);
        }
        else if ((RemainingTimeInState >= SecondsToStateChange - 10f) && (preStatechangeAction))
        {
            SpawnTrashOverTime();
            GameInfo.PlantDestroyer.DestroyTreesInAlive1();
            preStatechangeAction = false;
        }
        // else spawn small Trash every time spawnTiming is hit;
        else
        {
            SpawnTrashOverTime();

            if (LastBalanceInState() >= timeBetweenBalancing || lastbaBalanceUpdate < 0f)  // Check if enough time has elapsed since last Balance spawn. Or its the first Balance spawn
            {
                Debug.Log("Balancing is triggered");
                if (LevelBalancing.GetBalanceVariance() < 0f)    // Check if there is need for Balance | Look up description in LevelBalancing Class for more info
                {
                    GameInfo.TrashSpawner.SpawnOnTimer();
                }
                else if (LevelBalancing.GetBalanceVariance() > (Trees.startingNatureValue / 100f * 30f))
                {
                    Debug.Log("Balancing is executing.");
                    GameInfo.PlantDestroyer.DestroyRandomTreeInRisingState();
                }
                lastbaBalanceUpdate = GameInfo.SpentSecondsIngame;
            }
        }

        return(this);
    }
Beispiel #3
0
    private void UpdateLevelTimer(float totalSeconds)
    {
        int minutes = Mathf.FloorToInt(totalSeconds / 60f);
        int seconds = Mathf.FloorToInt(totalSeconds % 60f);

        if (seconds == 60)
        {
            seconds  = 0;
            minutes += 1;
        }
        debugInfo.text = $"Time: {minutes.ToString("00")}:{seconds.ToString("00")} \nSTATE: {currentState.ToString()} " +
                         $"\nNature: {LevelBalancing.GetCurrentNatureValue()}\nTrash: {LevelBalancing.GetCurrentTrashValue()}\nBalanceValue: {LevelBalancing.GetBalanceVariance()}";
    }