private IEnumerator ScrollSpeedFader(float to, float duration, FadingType type)
        {
            float start = _scrollingSpeed;
            float t     = 0;

            while (t < duration)
            {
                float tn = t / duration;
                switch (type)
                {
                case FadingType.LINEAR:
                    _scrollingSpeed = Maths.Lerp(start, to, tn);
                    break;

                case FadingType.SMOOTH_STEP:
                    _scrollingSpeed = Maths.Lerp(start, to, Maths.SmoothStep(0, 1, tn));
                    break;

                case FadingType.FADE_IN:
                    _scrollingSpeed = Maths.Lerp(start, to, Maths.EaseIn(tn));
                    break;

                case FadingType.FADE_OUT:
                    _scrollingSpeed = Maths.Lerp(start, to, Maths.EaseOut(tn));
                    break;
                }

                t += Program.UpdateTime.DeltaTime;
                yield return(null);
            }

            _scrollingSpeed = to;
            _fade           = null;
        }
Exemple #2
0
        private IEnumerator WarningScreen(Animation anim)
        {
            Vector2 startPos = new Vector2(0, -80);
            Vector2 endPos   = new Vector2(0, -2);

            _warning.Animation = anim;
            _warning.Spawn(startPos, Vector2.zero);
            yield return(Program.UpdateTime.WaitForSeconds(2.0f));

            float t        = 0;
            float duration = 0.5f;
            float delta;

            while (t < duration)
            {
                delta = Program.UpdateTime.DeltaTime;
                float n = t / duration;

                _warning.Update(delta);
                _warning.Position = Vector2.Lerp(startPos, endPos, Maths.SmoothStep(0.0f, 1.0f, n));
                t += delta;
                yield return(null);
            }

            startPos          = endPos;
            _warning.Position = startPos;
            endPos            = new Vector2(0, 10);

            duration = 2.5f;
            t        = 0;
            while (t < duration)
            {
                delta = Program.UpdateTime.DeltaTime;
                float n = t / duration;

                _warning.Update(delta);
                _warning.Position = Vector2.Lerp(startPos, endPos, n);
                t += delta;
                yield return(null);
            }


            startPos          = endPos;
            _warning.Position = startPos;
            endPos            = new Vector2(0, 90);

            duration = 2.0f;
            t        = 0;

            float multiplier = 1.0f;

            while (t < duration)
            {
                delta = Program.UpdateTime.DeltaTime;
                float n = t / duration;

                _warning.Update(delta);
                _warning.Position = Vector2.Lerp(startPos, endPos, n);
                t += delta * multiplier;

                multiplier = Maths.Lerp(1.0f, 5.0f, n);
                yield return(null);
            }

            _warning.Despawn(false);
        }