Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        InputHandler.HandleInputs();
        CameraHandler.Update();
        DisasterHandler.Update();

        switch (GameState)
        {
        case GameState.Idle:
            break;

        case GameState.DayCycle:
            // Time update
            CurCycleRealTime    += Time.deltaTime;
            _lastUpdateCycleTime = CycleTime;
            CycleTime            = (int)(CurCycleRealTime / CYCLE_REAL_TIME * CYCLE_TIME);

            // Cycle actions
            foreach (Building b in Buildings)
            {
                if (b.Health > 0 && b.CycleActionTime < CycleTime && b.CycleActionTime >= _lastUpdateCycleTime)
                {
                    b.CycleAction();
                }
            }
            foreach (Disaster d in CycleDisasters)
            {
                if (d.CycleTime < CycleTime && d.CycleTime >= _lastUpdateCycleTime)
                {
                    DisastersToShow.Enqueue(d);
                }
            }

            if (DisastersToShow.Count > 0)
            {
                ShowDisaster(DisastersToShow.Dequeue());
            }

            // New day
            if (CurCycleRealTime >= CYCLE_REAL_TIME)
            {
                StartNewDay();
            }

            // Light adjustments
            Vector3 sunRotation = Vector3.Lerp(new Vector3(50, -30, 0), new Vector3(410, 330, 0), CurCycleRealTime / CYCLE_REAL_TIME);
            Sun.transform.rotation = Quaternion.Euler(sunRotation);
            if (sunRotation.x < 140)
            {
                Moon.intensity = 0f;
            }
            else if (sunRotation.x < 220)
            {
                Moon.intensity = (sunRotation.x - 140) / 80 * MAX_MOON_INTENSITY;
            }
            else if (sunRotation.x < 320)
            {
                Moon.intensity = MAX_MOON_INTENSITY;
            }
            else if (sunRotation.x < 400)
            {
                Moon.intensity = MAX_MOON_INTENSITY - ((sunRotation.x - 320) / 80 * MAX_MOON_INTENSITY);
            }
            else
            {
                Moon.intensity = 0f;
            }
            if ((int)sunRotation.x == 180)
            {
                foreach (City city in Cities)
                {
                    city.CityLight.intensity = 1f;
                }
            }
            if ((int)sunRotation.x == 360)
            {
                foreach (City city in Cities)
                {
                    city.CityLight.intensity = 0f;
                }
            }
            break;

        case GameState.AlertFlash:
            _disasterTime += Time.deltaTime;
            if (_disasterTime > DISASTER_ALERT_TIME)
            {
                _disasterTime = 0f;
                CameraHandler.MoveTo(ActiveDisaster.Center);
                GameState = GameState.MoveToDisaster;
            }
            break;

        case GameState.MoveToDisaster:
            if (CameraHandler.State == CameraState.Idle)
            {
                _disasterTime += Time.deltaTime;
                if (_disasterTime > DISASTER_START_TIME_OFFSET)
                {
                    ActiveDisaster.CastVisualEffect();
                    ActiveDisaster.ApplyEffect();
                    GameState     = GameState.DisasterOccuring;
                    _disasterTime = 0f;
                }
            }
            break;

        case GameState.DisasterOccuring:
            _disasterTime += Time.deltaTime;
            if (_disasterTime > DISASTER_END_TIME_OFFSET)
            {
                GameUI.Alert_StopFlash();
                GameState = GameState.DayCycle;
            }

            break;
        }
    }