void generatePP()
        {
            using (var pool = new OsbSpritePool(GetLayer("hl"), "sb/pp.png", OsbOrigin.Centre, (sprite, startTime, endTime) =>
            {
            }))
            {
                foreach (var hitobject in Beatmap.HitObjects)
                {
                    if ((hitobject.StartTime >= 33981 - 5 && hitobject.StartTime < 36381 + 5) ||
                        ((hitobject.StartTime >= 41181 - 5 && hitobject.StartTime < 42381 + 5) ||
                         (hitobject.StartTime >= 43581 - 5 && hitobject.StartTime < 52506 + 5) ||
                         (hitobject.StartTime >= 67582 - 5 && hitobject.StartTime < 76132 + 5))
                        )
                    {
                        for (var dotNum = 0; dotNum <= Random(5, 20); dotNum++)
                        {
                            var angle    = Random(0, Math.PI * 2);
                            var radius   = Random(50, 200);
                            var position = new Vector2(
                                hitobject.Position.X + (float)Math.Cos(angle) * radius,
                                hitobject.Position.Y + (float)Math.Sin(angle) * radius
                                );

                            var sprite = pool.Get(hitobject.StartTime, hitobject.StartTime + 1000);
                            sprite.Move(OsbEasing.OutExpo, hitobject.StartTime, hitobject.StartTime + 1000, hitobject.Position, position);
                            sprite.Fade(hitobject.StartTime, hitobject.StartTime + 1000, 1, 0);
                        }
                    }
                }
            }
        }
        void generatePl()
        {
            using (var pool = new OsbSpritePool(GetLayer("hl"), "sb/pl.png", OsbOrigin.Centre, (sprite, startTime, endTime) =>
            {
            }))
            {
                foreach (var hitobject in Beatmap.HitObjects)
                {
                    if ((hitobject.StartTime >= 9390 - 5 && hitobject.StartTime < 9990 + 5) ||
                        (hitobject.StartTime >= 28582 - 5 && hitobject.StartTime < 29107 + 5) ||
                        (hitobject.StartTime >= 60381 - 5 && hitobject.StartTime < 67581 + 5) ||
                        (hitobject.StartTime >= 52582 - 5 && hitobject.StartTime < 53182 + 5)
                        )
                    {
                        var sprite = pool.Get(hitobject.StartTime, hitobject.EndTime + 200);
                        sprite.Scale(hitobject.StartTime, hitobject.StartTime + 100, 0, 1);
                        sprite.Fade(hitobject.StartTime, 1);
                        sprite.Color(hitobject.StartTime, hitobject.Color);
                        sprite.Fade(hitobject.EndTime, hitobject.EndTime + 200, 1, 0);
                        sprite.Move(hitobject.StartTime, hitobject.Position);

                        if (hitobject is OsuSlider)
                        {
                            var pos = hitobject.Position;
                            for (var i = hitobject.StartTime; i <= hitobject.EndTime; i += tick(0, 4))
                            {
                                sprite.Move(i, i + tick(0, 4), hitobject.PositionAtTime(i), hitobject.PositionAtTime(i + tick(0, 4)));
                            }
                        }
                    }
                }
            }
        }
        void generateRings()
        {
            using (var pool = new OsbSpritePool(GetLayer("hl"), "sb/r.png", OsbOrigin.Centre, (sprite, startTime, endTime) =>
            {
            }))
            {
                foreach (var hitobject in Beatmap.HitObjects)
                {
                    if (
                        #region ringTimes
                        InTime(hitobject.StartTime, 9990, 9990) ||
                        InTime(hitobject.StartTime, 19590, 19590) ||
                        InTime(hitobject.StartTime, 28881, 28881) ||
                        InTime(hitobject.StartTime, 31582, 31582) ||
                        InTime(hitobject.StartTime, 33981, 33981) ||
                        InTime(hitobject.StartTime, 34281, 34281) ||
                        InTime(hitobject.StartTime, 34581, 34581) ||
                        InTime(hitobject.StartTime, 34881, 34881) ||
                        InTime(hitobject.StartTime, 35181, 35181) ||
                        InTime(hitobject.StartTime, 35481, 35481) ||
                        InTime(hitobject.StartTime, 35781, 35781) ||
                        InTime(hitobject.StartTime, 36081, 36081) ||
                        InTime(hitobject.StartTime, 36381, 36381) ||
                        InTime(hitobject.StartTime, 38782, 38782) ||
                        InTime(hitobject.StartTime, 41181, 41181) ||
                        InTime(hitobject.StartTime, 41481, 41481) ||
                        InTime(hitobject.StartTime, 41781, 41781) ||
                        InTime(hitobject.StartTime, 42081, 42081) ||
                        InTime(hitobject.StartTime, 42381, 42381) ||
                        InTime(hitobject.StartTime, 42681, 42681) ||
                        InTime(hitobject.StartTime, 42981, 42981) ||
                        InTime(hitobject.StartTime, 43281, 43281) ||
                        InTime(hitobject.StartTime, 43581, 43581) ||
                        InTime(hitobject.StartTime, 44781, 44781) ||
                        InTime(hitobject.StartTime, 45981, 45981) ||
                        InTime(hitobject.StartTime, 47181, 47181) ||
                        InTime(hitobject.StartTime, 48381, 48381) ||
                        InTime(hitobject.StartTime, 49582, 49582) ||
                        InTime(hitobject.StartTime, 50782, 50782) ||
                        InTime(hitobject.StartTime, 51982, 51982) ||
                        InTime(hitobject.StartTime, 53182, 53182) ||
                        InTime(hitobject.StartTime, 54382, 54382) ||
                        InTime(hitobject.StartTime, 55582, 55582) ||
                        InTime(hitobject.StartTime, 56782, 56782) ||
                        InTime(hitobject.StartTime, 57982, 57982) ||
                        InTime(hitobject.StartTime, 59182, 59182) ||
                        InTime(hitobject.StartTime, 67582, 67582)

                        #endregion ringTimes
                        )
                    {
                        var sprite = pool.Get(hitobject.StartTime, hitobject.EndTime + 950);
                        sprite.Scale(OsbEasing.OutExpo, hitobject.StartTime, hitobject.StartTime + 950, 0, 0.5);

                        sprite.Fade(hitobject.StartTime, hitobject.StartTime + 950, 1, 0);
                        sprite.Move(hitobject.StartTime, hitobject.Position);
                    }
                }
            }
        }
 public void Hitlight(OsbSpritePool pool, List <intRange> ranges)
 {
     using (pool)
     {
         foreach (var hitobject in MainStoryboard.Instance.Beatmap.HitObjects)
         {
             foreach (var range in ranges)
             {
                 if (InTime((int)hitobject.StartTime, range.from, range.to, 5) ||
                     InTime((int)hitobject.EndTime, range.from, range.to, 5))
                 {
                     var sprite = pool.Get(hitobject.StartTime - 100, hitobject.EndTime + 100);
                     sprite.Color(hitobject.StartTime - 100, hitobject.Color);
                     sprite.Fade(hitobject.StartTime - 100, hitobject.EndTime + 100, 1, 0);
                     sprite.Scale(hitobject.StartTime - 100, hitobject.StartTime, 0, 0.25);
                     sprite.Move(hitobject.StartTime - 100, hitobject.Position);
                     if (hitobject is OsuSlider)
                     {
                         for (var i = hitobject.StartTime; i < hitobject.EndTime; i += GetBeatDuration((int)hitobject.StartTime, 4))
                         {
                             sprite.Move(
                                 i,
                                 i + GetBeatDuration((int)i, 4),
                                 hitobject.PositionAtTime(i),
                                 hitobject.PositionAtTime(i + GetBeatDuration((int)i, 4))
                                 );
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #5
0
        public void GenerateParticles(double startTime, double endTime, bool fromTop = false)
        {
            using (var pool = new OsbSpritePool(layer, "sb/pixel.png", OsbOrigin.Centre, (sprite, sTime, eTime) => {
                sprite.Fade(sTime, Random(0.2f, 0.9f));
                sprite.Scale(sTime, Random(20f, 80f));
                sprite.MoveX(sTime, Random(-107, 757));

                if (eTime > endTime - beatduration * 4) //Hide sprites if they cross the end time
                {
                    sprite.Fade(endTime, 0f);
                }
            })){
                for (var sTime = (double)startTime; sTime <= endTime - beatduration * 4; sTime += beatduration / 2f)
                {
                    var baseSpeed = Random(40, 120);
                    var eTime     = sTime + Math.Ceiling(620f / baseSpeed) * beatduration;

                    if (eTime > 313864 && sTime < 314922) //Add bonus time for the movement stop section in the second kiai
                    {
                        eTime += 1058 * 2;
                    }

                    var sprite = pool.Get(sTime, eTime);

                    var moveSpeed   = baseSpeed * (fromTop ? 1 : -1);
                    var currentTime = sTime + (sTime - offset) % beatduration;

                    sprite.MoveY(sTime, fromTop ? -60 : 540);
                    while (fromTop ? sprite.PositionAt(currentTime).Y <540 : sprite.PositionAt(currentTime).Y> -60)
                    {
                        if (currentTime > 313864 && currentTime < 314922)   //This is a silent part in the second kiai. No movement wanted
                        {
                            currentTime += beatduration;
                            continue;
                        }

                        if (fromTop && currentTime > endTime - beatduration * 4) //Kiai fading out, stop movement at once (sprite needs to stay for a bit longer)
                        {
                            break;
                        }

                        var longHit = IsStrongHit(currentTime);

                        var yPos = sprite.PositionAt(currentTime).Y;
                        var yRot = sprite.RotationAt(currentTime);

                        sprite.MoveY(longHit ? OsbEasing.OutCubic : OsbEasing.OutExpo, currentTime, currentTime + beatduration, yPos, yPos + moveSpeed * (longHit ? 1.1 : 1));
                        sprite.Rotate(longHit ? OsbEasing.Out : OsbEasing.OutExpo, currentTime, currentTime + beatduration, yRot, yRot + Math.PI * 0.25f);

                        currentTime += beatduration;
                    }

                    if (Random(0, 4) > 0) //HACK move the time back in order to increase the particle count without running into syncing issues
                    {
                        sTime -= beatduration / 2f;
                    }
                }
            }
        }
    public void DarkyRingHit(OsbSpritePool pool, List <int> timeList, double sizeStart, double sizeEnd)
    {
        using (pool)
        {
            foreach (var hitobject in MainStoryboard.Instance.Beatmap.HitObjects)
            {
                foreach (var time in timeList)
                {
                    if (InTime((int)hitobject.StartTime, time, 5))
                    {
                        var sprite = pool.Get(
                            hitobject.StartTime,
                            hitobject.EndTime +
                            GetBeatDuration((int)hitobject.StartTime, 1) +
                            (GetBeatDuration((int)hitobject.StartTime, 4) * 3));

                        sprite.Scale(OsbEasing.OutExpo, hitobject.StartTime, hitobject.EndTime +
                                     GetBeatDuration((int)hitobject.StartTime, 1) +
                                     (GetBeatDuration((int)hitobject.StartTime, 4) * 3), sizeStart, sizeEnd);

                        sprite.Fade(hitobject.StartTime, hitobject.EndTime +
                                    GetBeatDuration((int)hitobject.StartTime, 1) +
                                    (GetBeatDuration((int)hitobject.StartTime, 4) * 3), 1, 0);
                        sprite.Move(hitobject.StartTime, hitobject.Position);
                    }
                    else if (InTime((int)hitobject.EndTime, time, 5))
                    {
                        var sprite = pool.Get(
                            hitobject.EndTime,
                            hitobject.EndTime +
                            GetBeatDuration((int)hitobject.StartTime, 1) +
                            (GetBeatDuration((int)hitobject.StartTime, 4) * 3));

                        sprite.Scale(OsbEasing.OutExpo, hitobject.EndTime, hitobject.EndTime +
                                     GetBeatDuration((int)hitobject.EndTime, 1) +
                                     (GetBeatDuration((int)hitobject.EndTime, 4) * 3), sizeStart, sizeEnd);

                        sprite.Fade(hitobject.EndTime, hitobject.EndTime +
                                    GetBeatDuration((int)hitobject.EndTime, 1) +
                                    (GetBeatDuration((int)hitobject.EndTime, 4) * 3), 1, 0);
                        sprite.Move(hitobject.EndTime, hitobject.EndPosition);
                    }
                }
            }
        }
    }
    public void CustomParticles(OsbSpritePool pool, ParticleParamaters paramaters)
    {
        using (pool)
        {
            var timeStep = paramaters.duration / paramaters.particleAmmount;
            for (double time = paramaters.startTime; time <= paramaters.endTime; time += timeStep)
            {
                var particleEndTime = time + paramaters.duration;
                var sprite          = pool.Get(time, particleEndTime);
                var startX          = paramaters.randomX ?
                                      Random(paramaters.Positions.from.X, paramaters.Positions.to.X)
                        : paramaters.Positions.from.X;
                var startY = paramaters.randomY ?
                             Random(paramaters.Positions.from.Y, paramaters.Positions.to.Y)
                        : paramaters.Positions.from.Y;

                var endX = paramaters.randomX ?
                           Random(paramaters.Positions.from.X, paramaters.Positions.to.X)
                        : paramaters.Positions.to.X;
                var endY = paramaters.sameYEnd ?
                           startY
                    : paramaters.randomYEnd ?
                           Random(paramaters.Positions.from.Y, paramaters.Positions.to.Y)
                        : paramaters.Positions.to.Y;

                sprite.Move(paramaters.easing,
                            time, particleEndTime,
                            startX, startY, endX, endY);
                sprite.Fade(time, paramaters.fade);
                sprite.Fade(particleEndTime, 0);

                if ((bool)paramaters.randomRotation == true)
                {
                    sprite.Rotate(
                        paramaters.easing,
                        time, particleEndTime,
                        DegreesToRadians(
                            Random(((Vector2)paramaters.rotation).X, ((Vector2)paramaters.rotation).Y)),
                        DegreesToRadians(
                            Random(((Vector2)paramaters.rotation).X, ((Vector2)paramaters.rotation).Y)));
                }
                else
                {
                    sprite.Rotate(
                        paramaters.easing,
                        time, particleEndTime,
                        DegreesToRadians(((Vector2)paramaters.rotation).X),
                        DegreesToRadians(((Vector2)paramaters.rotation).Y));
                }

                //  if(Random(0, 4) > 0) //HACK move the time back in order to increase the particle count without running into syncing issues
                //           time -= GetBeatDuration((int)time, 2);
            }
        }
    }
        public void GenerateStars(double time, double duration, OsbSpritePool pool, Vector2 vector)
        {
            var sprite    = pool.Get(time, time + duration);
            var randScale = Random(0.3, 0.5);

            sprite.Fade(0, 0);
            sprite.Fade(time + duration - 900, time + duration - 700, 0, 0.7);
            sprite.Fade(time + duration - 700, time + duration - 200, 0.7, 0);
            var finalX = Random(-200, 850);
            var finalY = Random(138, 334);

            sprite.Move(time, time + duration, vector, new Vector2(finalX, finalY));
            sprite.Scale(time + duration - 900, time + duration - 200, randScale, Random(0.6, 1));
            var angleRadians = Math.Atan2(vector.Y - finalY, vector.X - finalX);

            sprite.Rotate(time, angleRadians);
        }
    public void DarkyRingHit(OsbSpritePool pool, int startTime, int endTime, double sizeStart, double sizeEnd)
    {
        using (pool)
        {
            foreach (var hitobject in MainStoryboard.Instance.Beatmap.HitObjects)
            {
                if (InTime((int)hitobject.StartTime, startTime, 5))
                {
                    var sprite = pool.Get(hitobject.StartTime, endTime);
                    sprite.Scale(OsbEasing.OutExpo, hitobject.StartTime, endTime, sizeStart, sizeEnd);

                    sprite.Fade(hitobject.StartTime, endTime, 1, 0);
                    sprite.Move(hitobject.StartTime, hitobject.Position);
                }
            }
        }
    }
Exemple #10
0
        public void GenerateStars(double time, double duration, OsbSpritePool pool, Vector2 vector, Vector2 vector2)
        {
            List <OsbEasing> easing = new List <OsbEasing>();

            easing.Add(OsbEasing.InSine);
            easing.Add(OsbEasing.InCubic);
            easing.Add(OsbEasing.InQuad);
            var randX     = Random(vector.X, vector2.X);
            var randY     = Random(vector.Y, vector2.Y);
            var sprite    = pool.Get(time, time + duration);
            var randScale = Random(0.03, 0.07);
            var randIndex = Random(0, easing.Count);

            sprite.Fade(easing[randIndex], time, time + duration, 1, 0);
            sprite.Move(time, randX, randY);
            sprite.Scale(time, randScale);
            sprite.Rotate(time, Random(0, 2));
        }
Exemple #11
0
        public override void Generate()
        {
            var layer = GetLayer("");

            using (var pool = new OsbSpritePool(layer, Path, OsbOrigin.Centre, (sprite, startTime, endTime) => {
                // This action runs for every sprite created from the pool, after all of them are created (AFTER the for loop below).

                // It is intended to set states common to every sprite:
                // In this exemple, this handles cases where all sprites will have the same color / opacity / scale / rotation / additive mode.

                // Note that the pool is in a using block, this is necessary to run this action.

                // Initial setup.
                sprite.Scale(27551, 0);
            }))

            {
                var timeStep = particleDuration / particleAmount;
                for (double startTime = 27551; startTime < 49369 - particleDuration; startTime += timeStep)
                {
                    var endTime = startTime + particleDuration;

                    // This is where sprites are created from the pool.
                    // Commands here are specific to each sprite.
                    var sprite = pool.Get(startTime, endTime);
                    var x      = Random(0, 640);
                    var y      = Random(0, 480);
                    while (x > 140 && x < 500 && y > 60 && y < 420)   // real values: (132, 508, 52, 427)
                    {
                        x = Random(0, 640);
                        y = Random(0, 480);
                    }
                    var fadeTime = Math.Max(startTime, startTime + fadeInDuration);

                    sprite.Move(startTime, x, y);

                    sprite.Fade(OsbEasing.In, startTime, fadeTime, 0, 1);
                    sprite.Scale(OsbEasing.OutElasticHalf, startTime, fadeTime, 0, 1);
                    sprite.Fade(OsbEasing.In, fadeTime, fadeTime + fadeOutDuration, 1, 0);
                    sprite.Scale(OsbEasing.InExpo, fadeTime, fadeTime + fadeOutDuration, 1, 0);
                }
            }
        }
Exemple #12
0
        void kiaiParticles(Double StartTime, double EndTime)
        {
            var particleCount    = 250;
            var particleDuration = 630;

            using (var pool = new OsbSpritePool(backLayer, "sb/pl.png", OsbOrigin.Centre, (sprite, startTime, endTime) =>
            {
                sprite.Color(startTime, new Color4(255, 226, 198, 255));
            }))
            {
                var timeStep = particleDuration / particleCount;
                for (var startTime = (double)StartTime - particleDuration; startTime <= EndTime - particleDuration; startTime += timeStep)
                {
                    var endTime = startTime + (particleDuration + Random(-55, 330));

                    var sprite = pool.Get(startTime, endTime);

                    var startX = Random(-107, 747);
                    var startY = 520;
                    var endX   = startX;
                    var endY   = -100;
                    sprite.Scale(startTime, Random(0.025, 0.15));
                    sprite.Move(startTime, endTime, startX, startY, endX, endY);
                }
            }

            if (StartTime == 122754)
            {
                var plate = kiaiLayer.CreateSprite("sb/p.png");
                plate.ScaleVec(121375, new Vector2(854, 480));
                plate.Fade(121375, 1);
                plate.Fade(122754, 0);
                plate.Color(121892, 122409, Color4.Black, Color4.White);
            }
            if (StartTime == 198616)
            {
                var plate = kiaiLayer.CreateSprite("sb/p.png");
                plate.ScaleVec(197237, new Vector2(854, 480));
                plate.Fade(197237, 1);
                plate.Fade(198616, 0);
                plate.Color(197237, Color4.Black);
            }
        }
    /// <summary>
    /// Creates litle particles that dispirse from the hitobject and ease into the centre location
    /// </summary>
    public void PPHitLight(OsbSpritePool pool, List <intRange> ranges, intRange particleAmmount, Vector2 CentreLocation,
                           OsbEasing easing = OsbEasing.None, int duration = 1000)
    {
        // Only effect hti object start positions.
        using (pool)
        {
            foreach (var hitobject in MainStoryboard.Instance.Beatmap.HitObjects)
            {
                foreach (var range in ranges)
                {
                    if (InTime((int)hitobject.StartTime, range.from, range.to, 5) ||
                        InTime((int)hitobject.EndTime, range.from, range.to, 5))
                    {
                        for (int i = 0; i < Random(particleAmmount.from, particleAmmount.to); i++)
                        {
                            var angle    = Random(0, Math.PI * 2);
                            var radius   = Random(50, 200);
                            var position = new Vector2(
                                hitobject.Position.X + (float)Math.Cos(angle) * radius,
                                hitobject.Position.Y + (float)Math.Sin(angle) * radius
                                );

                            var sprite = pool.Get(hitobject.StartTime - 100, hitobject.StartTime + duration * 1.5);
                            sprite.Fade(hitobject.StartTime, 1);
                            sprite.Move(OsbEasing.OutExpo, hitobject.StartTime, hitobject.StartTime + duration, hitobject.Position, position);
                            sprite.Move(OsbEasing.None,
                                        hitobject.StartTime + duration, hitobject.StartTime + duration * 1.5, position, CentreLocation);

                            if ((hitobject.StartTime + duration * 1.5) > range.to)
                            {
                                sprite.Fade(hitobject.StartTime + 100, range.to, 1, 0);
                            }
                            else
                            {
                                sprite.Fade(hitobject.StartTime + duration * 1.5, 0);
                            }
                        }
                    }
                }
            }
        }
    }
Exemple #14
0
        void freestyleSliders()
        {
            var sliderTimes = new List <double> {
                77237, 78616, 79996, 80685, 80858, 81030
            };

            using (var pool = new OsbSpritePool(hitLayer, "sb/pl.png", OsbOrigin.Centre, (sprite, startTime, endTime) =>
            {
            }))
            {
                foreach (var hitobject in Beatmap.HitObjects)
                {
                    if (hitobject is OsuSlider)
                    {
                        foreach (var sliderTime in sliderTimes)
                        {
                            if ((hitobject.StartTime >= 77237 - 5 && hitobject.StartTime < 86892 + 5) ||
                                (hitobject.StartTime >= 88271 - 5 && hitobject.StartTime < 97927) ||
                                (hitobject.StartTime >= 143444 - 5 && hitobject.StartTime < 153099) ||
                                (hitobject.StartTime >= 154478 - 5 && hitobject.StartTime < 165513) ||
                                (hitobject.StartTime >= 104823 - 5 && hitobject.StartTime < 105513)
                                )
                            {
                                //Log($"We got one at: {hitobject.StartTime}");
                                for (var time = hitobject.StartTime; time <= hitobject.EndTime; time += tick(0, 12))
                                {
                                    var sprite = pool.Get(time, hitobject.EndTime + (time - hitobject.StartTime + 120));
                                    sprite.Scale(time, time + 50, 0, 0.5);
                                    sprite.Fade(time, 1);
                                    sprite.Color(time, hitobject.Color);
                                    sprite.Fade(hitobject.EndTime, hitobject.EndTime + (time - hitobject.StartTime + 120), 1, 0);
                                    sprite.Move(time, hitobject.PositionAtTime(time));
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #15
0
        public override void Generate()
        {
            var layer = GetLayer("");

            using (var pool = new OsbSpritePool(layer, "sb/sprites/toDown.png", OsbOrigin.Centre, (sprite, startTime, endTime) => {
                // This action runs for every sprite created from the pool, after all of them are created (AFTER the for loop below).

                // It is intended to set states common to every sprite:
                // In this exemple, this handles cases where all sprites will have the same color / opacity / scale / rotation / additive mode.

                // Note that the pool is in a using block, this is necessary to run this action.

                // Initial setup.
                sprite.Scale(27551, 0);
            }))

            {
                var timeStep = particleDuration / particleAmount;
                for (double startTime = 27551; startTime < 49369 - particleDuration; startTime += timeStep)
                {
                    var endTime = startTime + particleDuration;

                    // This is where sprites are created from the pool.
                    // Commands here are specific to each sprite.
                    var sprite = pool.Get(startTime, endTime);
                    var x      = Random(0, 640);
                    var y      = Random(0, 480);
                    while (x > 140 && x < 500 && y > 60 && y < 420)
                    {
                        x = Random(0, 640);
                        y = Random(0, 480);
                    }

                    var arrowCount = Random(3, 6);

                    List <OsbSprite> arrowList = new List <OsbSprite>();

                    while (arrowCount >= 0)
                    {
                        arrowList.Add(layer.CreateSprite("sb/sprites/toDown.png", OsbOrigin.Centre));
                        arrowCount--;
                    }

                    var loopAmount = Random(2, 5);

                    for (int i = 0; i < arrowList.Count; i++)
                    {
                        OsbSprite arrow = arrowList[i];


                        arrow.Scale(startTime, 0.2);

                        arrow.StartLoopGroup(0, loopAmount);

                        arrow.Fade(OsbEasing.InOutExpo, startTime, startTime + 300 + 2 * i, 0, 1);
                        arrow.Move(OsbEasing.InOutExpo, startTime, startTime + 300 + 2 * i, x, y, x, y + 10 + i * 15);

                        arrow.Fade(OsbEasing.InExpo, startTime + 300 + 2 * i, startTime + 600 + 2 * i, 1, 0);
                        arrow.Move(OsbEasing.InExpo, startTime + 300 + 2 * i, startTime + 600 + 2 * i, x, y + 10 + i * 15, x, y + 20 + i * 26);
                        arrow.EndGroup();
                    }
                }
            }
        }
Exemple #16
0
        private void ParticleGen(int StartTime, int EndTime)
        {
            if (StartTime == EndTime)
            {
                StartTime = (int)Beatmap.HitObjects.First().StartTime;
                EndTime   = (int)Beatmap.HitObjects.Last().EndTime;
            }
            EndTime   = Math.Min(EndTime, (int)AudioDuration);
            StartTime = Math.Min(StartTime, EndTime);

            // This is an example of using a particle pool.
            // Sprites using the same layer, path and origin can be reused as if they were multiple sprites.

            //Line Stuff
            // var lines = new Dictionary<OsbSprite, OsbSprite>();
            var pos       = new Dictionary <OsbSprite, Vector2d>();
            var connected = new Dictionary <int, List <OsbSprite> >();
            // Line stuff ends here

            var layer = GetLayer("");

            using (var pool = new OsbSpritePool(layer, ParticlePath, ParticleOrigin, (particle, startTime, endTime) =>
                                                { }))
            {
                for (int i = StartTime; i < (EndTime); i += TimeBetweenParticles)
                {
                    var RealTravelTime = RandomTravelTime ? Random(MinTravelTime, MaxTravelTime) : MinTravelTime;
                    var ParticleFade   = RandomParticleFade ? Random(ParticleFadeMin, ParticleFadeMax) : ParticleFadeMin;
                    // var LineFade = RandomLineFade ? Random(LineFadeMin, LineFadeMax) : LineFadeMin;
                    var particle = pool.Get(i, i + RealTravelTime);

                    // if (!lines.ContainsKey(particle))
                    // {
                    //     lines[particle] = layer.CreateSprite(LinePath, LineOrigin, new Vector2(320, 240));
                    //     pos[particle] = new Vector2d(320, 240);
                    // }
                    // var line = lines[particle];

                    particle.Color(i, ParticleColor);
                    // line.Color(i, LineColor);

                    if (StartScale == EndScale && StartScale != 1)
                    {
                        particle.Scale(i, StartScale);
                    }

                    if (StartRotation == EndRotation && StartRotation != 0)
                    {
                        particle.Rotate(i, MathHelper.DegreesToRadians(StartRotation));
                    }

                    if (StartScale != EndScale)
                    {
                        if (RandomScale)
                        {
                            particle.Scale(i, i + RealTravelTime, Random(StartScale, EndScale), Random(StartScale, EndScale));
                        }
                        else
                        {
                            particle.Scale(i, i + RealTravelTime, StartScale, EndScale);
                        }
                    }

                    if (StartRotation != EndRotation)
                    {
                        if (RandomRotation)
                        {
                            particle.Rotate(i, i + RealTravelTime, MathHelper.DegreesToRadians(Random(StartRotation, EndRotation)), MathHelper.DegreesToRadians(Random(StartRotation, EndRotation)));
                        }
                        else
                        {
                            particle.Rotate(i, i + RealTravelTime, MathHelper.DegreesToRadians(StartRotation), MathHelper.DegreesToRadians(EndRotation));
                        }
                    }

                    if (ParticleAdditive)
                    {
                        particle.Additive(i, i + RealTravelTime);
                    }

                    // if (ParticleAdditive)
                    // {
                    //     line.Additive(i, i + RealTravelTime);
                    // }

                    if (!RandomMovement)
                    {
                        var startX = RandomX ? Random(StartPosition.X, EndPosition.X) : StartPosition.X;
                        var startY = RandomY ? Random(EndPosition.Y, StartPosition.Y) : StartPosition.Y;
                        var endX   = RandomX ? startX : EndPosition.X;
                        var endY   = RandomY ? startY : EndPosition.Y;
                        particle.Move(i, i + RealTravelTime, startX, startY, endX, endY);
                    }

                    else
                    {
                        var lastX = Random(StartPosition.X, EndPosition.X);
                        var lastY = Random(StartPosition.Y, EndPosition.Y);

                        var UpdateRate   = 500;
                        var lastAngle    = 0d;
                        var lastDistance = 0d;

                        var rVec = MathHelper.DegreesToRadians(Random(0, 360));
                        var sVec = Random(1, 16);
                        var vX   = (Math.Cos(rVec) * sVec) / (TravelSpeed / 2);
                        var vY   = (Math.Sin(rVec) * sVec) / (TravelSpeed / 2);

                        var startPosition = new Vector2d(lastX, lastY);
                        pos[particle] = startPosition;
                        var endPosition = new Vector2d(lastX, lastY);

                        for (var t = i; t < i + RealTravelTime; t += UpdateRate)
                        {
                            var nextX = lastX + (vX / 10);
                            var nextY = lastY + (vY / 10);

                            // Line stuff
                            startPosition.X = lastX;
                            startPosition.Y = lastY;
                            // var ShowLines = false;

                            // foreach (var item in lines)
                            // {
                            //     if (item.Key == particle)
                            //     {
                            //         continue;
                            //     }
                            //     var spos = item.Key.PositionAt(t + UpdateRate);

                            //     if (!connected.ContainsKey(t))
                            //     {
                            //         connected[t] = new List<OsbSprite>();
                            //     }

                            //     if ((Math.Sqrt(Math.Pow(spos.Y - startPosition.Y, 2) + Math.Pow(spos.X - startPosition.X, 2))) < ConnectRadiusMin
                            //     && (Math.Sqrt(Math.Pow(spos.Y - startPosition.Y, 2) + Math.Pow(spos.X - startPosition.X, 2))) < ConnectRadiusMax)
                            //     {
                            //         if (!connected[t].Contains(particle))
                            //         {
                            //             endPosition.X = spos.X;
                            //             endPosition.Y = spos.Y;
                            //             ShowLines = false;
                            //             connected[t].Add(particle);
                            //             break;
                            //         }
                            //     }
                            // }

                            // if (!ShowLines)
                            // {
                            //     // line.Fade(i, 0);
                            //     endPosition.X = startPosition.X;
                            //     endPosition.Y = startPosition.Y;
                            // }
                            // else
                            // {
                            //     //line.Fade(i + RealTravelTime, LineFade);
                            // }

                            // Line stuff
                            // double distance = Math.Sqrt(Math.Pow(endPosition.Y - startPosition.Y, 2) + Math.Pow(endPosition.X - startPosition.X, 2));
                            // var angle = Math.Atan2((startPosition.Y - endPosition.Y), (startPosition.X - endPosition.X)) - Math.PI / 2f;

                            // line.ScaleVec(t, t + UpdateRate, lineThickness, lastDistance, lineThickness, distance);
                            // line.Rotate(t, t + UpdateRate, lastAngle, angle);
                            // line.Move(t, t + UpdateRate, lastX, lastY, nextX, nextY);;

                            // lastDistance = distance;
                            // lastAngle = angle;

                            particle.Move(t, t + UpdateRate, lastX, lastY, nextX, nextY);

                            vX += Random(-TravelSpeed, TravelSpeed) * UpdateRate / 1000;
                            vY += Random(-TravelSpeed, TravelSpeed) * UpdateRate / 1000;

                            lastX = nextX;
                            lastY = nextY;
                        }
                    }

                    if (i < EndTime - (FadeTimeIn + FadeTimeOut))
                    {
                        particle.Fade(i, i + FadeTimeIn, 0, ParticleFade);
                        // line.Fade(i, i + FadeTimeIn, 0, LineFade);
                        if (i < EndTime - RealTravelTime)
                        {
                            particle.Fade(i + RealTravelTime - FadeTimeOut, i + RealTravelTime, ParticleFade, 0);
                            // line.Fade(i + RealTravelTime - FadeTimeOut, i + RealTravelTime, LineFade, 0);
                        }
                        else
                        {
                            particle.Fade(EndTime - FadeTimeOut, EndTime, ParticleFade, 0);
                            // line.Fade(EndTime - FadeTimeOut, EndTime, LineFade, 0);
                        }
                    }
                    else
                    {
                        particle.Fade(i, 0);
                        // line.Fade(i, 0);
                    }
                }
            }
        }
Exemple #17
0
        public override void Generate()
        {
            Random rand = new Random();

            if (StartTime == EndTime)
            {
                StartTime = (int)Beatmap.HitObjects.First().StartTime;
                EndTime   = (int)Beatmap.HitObjects.Last().EndTime;
            }
            EndTime   = Math.Min(EndTime, (int)AudioDuration);
            StartTime = Math.Min(StartTime, EndTime);

            var particleDuration = ParticleDuration > 0 ? ParticleDuration :
                                   Beatmap.GetTimingPointAt(StartTime).BeatDuration * 4;

            // This is an example of using a sprite pool.
            // Sprites using the same layer, path and origin can be reused as if they were multiple sprites.

            var layer = GetLayer("");

            using (var pool = new OsbSpritePool(layer, Path, Origin, (sprite, startTime, endTime) =>
            {
                // This action runs for every sprite created from the pool, after all of them are created (AFTER the for loop below).

                // It is intended to set states common to every sprite:
                // In this example, this handles cases where all sprites will have the same color / opacity / scale / rotation / additive mode.

                // Note that the pool is in a using block, this is necessary to run this action.

                if (Color.R < 1 || Color.G < 1 || Color.B < 1)
                {
                    sprite.Color(startTime, Color);
                }

                if (Color.A < 1)
                {
                    sprite.Fade(startTime, Color.A);
                }

                if (StartScale == EndScale && StartScale != 1)
                {
                    sprite.Scale(startTime, StartScale);
                }

                if (StartRotation == EndRotation && StartRotation != 0)
                {
                    sprite.Rotate(startTime, MathHelper.DegreesToRadians(StartRotation));
                }

                if (Additive)
                {
                    sprite.Additive(startTime, endTime);
                }
            }))
            {
                var timeStep = particleDuration / ParticleAmount;
                for (var startTime = (double)StartTime; startTime <= EndTime - particleDuration; startTime += timeStep)
                {
                    var endTime = startTime + particleDuration;

                    // This is where sprites are created from the pool.
                    // Commands here are specific to each sprite.

                    // Note that you must know for how long you are going to use the sprite:
                    // startTime being the start time of the earliest command, endTime the end time of the last command.

                    // Sprites must also be created in order (startTime keeps increasing in each loop iteration),
                    // or sprites won't be properly reused.
                    var sprite = pool.Get(startTime, endTime);

                    var easing  = RandomEasing ? (OsbEasing)Random(1, 3) : Easing;
                    int numberX = rand.Next(-440, 840);
                    int numberY = rand.Next(-60, 540);
                    var endX    = numberX;
                    var endY    = numberY;
                    sprite.Move(easing, startTime, endTime, StartPositionX, StartPositionY, endX, endY);

                    if (FadeInDuration > 0 || FadeOutDuration > 0)
                    {
                        var fadeInTime  = startTime + FadeInDuration;
                        var fadeOutTime = endTime - FadeOutDuration;
                        if (fadeOutTime < fadeInTime)
                        {
                            fadeInTime = fadeOutTime = (fadeInTime + fadeOutTime) / 2;
                        }

                        sprite.Fade(easing, startTime, Math.Max(startTime, fadeInTime), 0, Color.A);
                        sprite.Fade(easing, Math.Min(fadeOutTime, endTime), endTime, Color.A, 0);
                    }

                    if (StartScale != EndScale)
                    {
                        if (RandomScale)
                        {
                            sprite.Scale(easing, startTime, endTime, Random(StartScale, EndScale), Random(StartScale, EndScale));
                        }
                        else
                        {
                            sprite.Scale(easing, startTime, endTime, StartScale, EndScale);
                        }
                    }

                    if (StartRotation != EndRotation)
                    {
                        if (RandomRotation)
                        {
                            sprite.Rotate(easing, startTime, endTime, MathHelper.DegreesToRadians(Random(StartRotation, EndRotation)), MathHelper.DegreesToRadians(Random(StartRotation, EndRotation)));
                        }
                        else
                        {
                            sprite.Rotate(easing, startTime, endTime, MathHelper.DegreesToRadians(StartRotation), MathHelper.DegreesToRadians(EndRotation));
                        }
                    }
                }
            }
        }
    public void MarchingParticle(Layers layer, int startTime, int endTime, int divisor, string spriteFile, ParticleGeneration particleGenType, ParticleDirection direction)
    {
        if (particleGenType == ParticleGeneration.Pool)
        {
            using (var pool = new OsbSpritePool(GetLayer(layer), spriteFile, OsbOrigin.Centre, (sprite, sTime, eTime) => {
                sprite.Fade(sTime, Random(0.2f, 0.9f));
                sprite.Scale(sTime, Random(20f, 80f));
                if (direction == ParticleDirection.Top || direction == ParticleDirection.Bottom)
                {
                    sprite.MoveX(sTime, Random(-107, 757));
                }
                else if (direction == ParticleDirection.Left || direction == ParticleDirection.Right)
                {
                    sprite.MoveY(sTime, Random(0, 512));
                }

                if (eTime > endTime - GetBeatDuration(startTime, divisor) * 4) //Hide sprites if they cross the end time
                {
                    sprite.Fade(endTime, 0f);
                }
            }))
            {
                for (var sTime = (double)startTime; sTime <= endTime - GetBeatDuration(startTime, 1) * 4; sTime += GetBeatDuration(startTime, 2))
                {
                    var baseSpeed = Random(40, 120);
                    var eTime     = sTime + Math.Ceiling(930f / baseSpeed) * GetBeatDuration(startTime, 1);


                    var sprite = pool.Get(sTime, eTime);

                    bool fromTop     = direction == ParticleDirection.Bottom || direction == ParticleDirection.Right;
                    var  moveSpeed   = baseSpeed * (fromTop ? 1 : -1);
                    var  currentTime = sTime + (sTime - GetOffset((int)sTime)) % GetBeatDuration(startTime, 1);

                    if (direction == ParticleDirection.Bottom || direction == ParticleDirection.Top)
                    {
                        sprite.MoveY(sTime, fromTop ? -60 : 540);
                    }
                    else if (direction == ParticleDirection.Left || direction == ParticleDirection.Right)
                    {
                        sprite.MoveX(sTime, fromTop ? -130 : 800);
                    }


                    if (direction == ParticleDirection.Bottom || direction == ParticleDirection.Top)
                    {
                        while (fromTop ? sprite.PositionAt(currentTime).Y <540 : sprite.PositionAt(currentTime).Y> -60)
                        {
                            var yPos = sprite.PositionAt(currentTime).Y;
                            var yRot = sprite.RotationAt(currentTime);

                            sprite.MoveY(OsbEasing.OutExpo, currentTime, currentTime + GetBeatDuration(startTime, 1), yPos, yPos + moveSpeed);
                            sprite.Rotate(OsbEasing.OutExpo, currentTime, currentTime + GetBeatDuration(startTime, 1), yRot, yRot + Math.PI * 0.25f);

                            currentTime += GetBeatDuration(startTime, 1);
                        }
                    }
                    else if (direction == ParticleDirection.Left || direction == ParticleDirection.Right)
                    {
                        while (fromTop ? sprite.PositionAt(currentTime).X <800 : sprite.PositionAt(currentTime).X> -120)
                        {
                            var xPos = sprite.PositionAt(currentTime).X;
                            var xRot = sprite.RotationAt(currentTime);

                            sprite.MoveX(OsbEasing.OutExpo, currentTime, currentTime + GetBeatDuration(startTime, 1), xPos, xPos + moveSpeed);
                            sprite.Rotate(OsbEasing.OutExpo, currentTime, currentTime + GetBeatDuration(startTime, 1), xRot, xRot + Math.PI * 0.25f);

                            currentTime += GetBeatDuration(startTime, 1);
                        }
                    }
                    //thx Darky
                    if (Random(0, 4) > 0) //HACK move the time back in order to increase the particle count without running into syncing issues
                    {
                        sTime -= GetBeatDuration(startTime, 2);
                    }
                }
            }
        }
    }
        private void Scene3(FontGenerator font)
        {
            /*=============================================
            *  //*               1st half
            *  =============================================*/
            generateBackgroundColor(23118, 24503, yellowColor);
            generateVerticalStripeBackground(24041, 25426, 60, blueColor, -60, true, false);
            generateVerticalStripeBackground(24965, 27272, 45, magentaColor, 45, false, false);
            generateHorizontalStripeBackground(26811, 28195, 60, blueMarineColor, false, false);
            generateVerticalStripeBackground(27734, 29118, 45, yellowColor, 30, true, false);
            generateVerticalStripeBackground(28657, 29580, 60, redColor, 0, true, false);
            generateBackgroundColor(29580, 30041, blueMarineColor);
            generateBackgroundColor(30041, 30272, magentaColor);
            generateBackgroundColor(30272, 30964, yellowColor);

            //* Lyrics
            generateScrollUpTiltedRightAlignedText(23118, 29580, "もうちょっとだけ\n大人でいたくて\n夏際くるぶしに\n少し掠るくらいで\n歩いている", 0.2f, new Vector2(270, 170), 228, -30, font, whiteColor);

            //* Sleeping girl
            var girl = GetLayer("elements").CreateSprite("sb/elements/s-girl.png", OsbOrigin.Centre);

            girl.Scale(23118, 0.5);
            girl.Fade(23118, 1);
            girl.Fade(30272, 0);
            girl.Move(23118, 30964, new Vector2(754, 480), new Vector2(615, 240));

            //* Ice cream
            var icecreamW = GetLayer("elements-w").CreateSprite("sb/elements/ice-cream-w.png", OsbOrigin.Centre);

            icecreamW.Scale(23118, 0.5);
            icecreamW.Fade(23118, 0);
            icecreamW.Fade(29811, 1);
            icecreamW.Fade(30964, 0);
            icecreamW.Color(29811, yellowColor);
            icecreamW.Color(30041, blueMarineColor);
            icecreamW.Color(30272, magentaColor);
            icecreamW.Move(23118, 30964, new Vector2(754, 480), new Vector2(615, 240));

            //* Girl white 2
            var girlW2 = GetLayer("elements-w").CreateSprite("sb/elements/s-girl-w-2.png", OsbOrigin.Centre);

            girlW2.Scale(23118, 0.5);
            girlW2.Fade(23118, 0);
            girlW2.Fade(30041, 1);
            girlW2.Fade(30964, 0);
            girlW2.Color(30041, yellowColor);
            girlW2.Color(30272, redColor);
            girlW2.Move(23118, 30964, new Vector2(754, 480), new Vector2(615, 240));

            //* Bubble
            var bubbleW = GetLayer("elements-w").CreateSprite("sb/elements/bubble-w.png", OsbOrigin.Centre);

            bubbleW.Scale(23118, 0.5);
            bubbleW.Color(30272, blueColor);
            bubbleW.Fade(23118, 0);
            bubbleW.Fade(30272, 1);
            bubbleW.Fade(30964, 0);
            bubbleW.Move(23118, 30964, new Vector2(754, 480), new Vector2(615, 240));

            /*=============================================
            *  //*              2nd half
            *  =============================================*/
            var mask = GetLayer("dropdown-element").CreateSprite("sb/elements/mask.png", OsbOrigin.BottomCentre);

            mask.Scale(30503, 0.2);
            generateDropdownTextAndElement(30503, 31426, "小さく", font, blueColor, mask);

            var fan = GetLayer("dropdown-element").CreateSprite("sb/elements/fan.png", OsbOrigin.BottomCentre);

            fan.Scale(31426, 0.2);
            generateDropdownTextAndElement(31426, 32349, "遠くで", font, yellowColor, fan);

            var bubble = GetLayer("dropdown-element").CreateSprite("sb/elements/bubble.png", OsbOrigin.BottomCentre);

            bubble.Scale(32349, 0.3);
            generateDropdownTextAndElement(32349, 33272, "何かが\n鳴った", font, redColor, bubble);

            var bg = GetLayer("dropdown-bg").CreateSprite("sb/common/pixel.png", OsbOrigin.TopLeft, new Vector2(-107, 0));

            bg.ScaleVec(OsbEasing.OutCirc, 33272, 33734, new Vector2(854, 0), new Vector2(854, 480));
            bg.Color(33272, blueMarineColor);
            bg.Fade(33272, 1);
            bg.Fade(37426, 0);

            //* Circles + elements
            var bigCircle = GetLayer("circle").CreateSprite("sb/common/circle.png", OsbOrigin.Centre);

            bigCircle.Scale(OsbEasing.OutCirc, 33272, 33734, 0.2, 1.05);
            bigCircle.Color(33272, yellowColor);
            bigCircle.Fade(33272, 1);
            bigCircle.Fade(37426, 0);

            var innerCircle = GetLayer("circle").CreateSprite("sb/common/circle.png", OsbOrigin.Centre);

            innerCircle.Scale(OsbEasing.OutCirc, 33272, 33734, 0, 0.95);
            innerCircle.Color(33272, whiteColor);
            innerCircle.Fade(33272, 1);
            innerCircle.Fade(37426, 0);

            var girlShadow = GetLayer("girl-on-circle").CreateSprite("sb/elements/s-girl-w.png", OsbOrigin.Centre, new Vector2(315, 243));

            girlShadow.Color(33734, yellowColor);
            girlShadow.Scale(OsbEasing.OutCirc, 33734, 34195, 0.0, 0.2);
            girlShadow.Scale(34195, 37426, 0.2, 0.17);
            girlShadow.Rotate(33734, 37426, 0, MathHelper.DegreesToRadians(-15));
            girlShadow.Fade(33734, 1);

            girl = GetLayer("girl-on-circle").CreateSprite("sb/elements/s-girl.png", OsbOrigin.Centre);
            girl.Scale(OsbEasing.OutCirc, 33734, 34195, 0.0, 0.2);
            girl.Scale(34195, 37426, 0.2, 0.17);
            girl.Rotate(33734, 37426, 0, MathHelper.DegreesToRadians(-15));
            girl.Fade(33734, 1);
            girl.Fade(37426, 0);

            //* Particle pool
            using (var pool = new OsbSpritePool(GetLayer("particles-on-circle"), "sb/common/circle.png", OsbOrigin.Centre, (sprite, startTime, endTime) =>
            {
                var rScale = Random(0.002, 0.006);
                var rColor = Random(0, 2);

                sprite.Scale(33272, rScale);
                sprite.Color(33272, rColor == 0 ? blueMarineColor : yellowColor);
            }))
            {
                var particleAmount = 500;
                for (int i = 0; i < particleAmount; i++)
                {
                    var sprite = pool.Get(33734, 37426);
                    var startX = Random(-107, 747);
                    var startY = Random(0, 480);

                    sprite.Move(33272, 37426, new Vector2(startX, startY), new Vector2(startX + Random(-50, 50), startY + Random(-50, 50)));
                    sprite.Fade(33272, 33734, 0, 1);
                    sprite.Fade(37426, 0);
                }
            }

            //* Lyrics
            generateRotatingSplitText(33734, 37426, 36964, "いつも横顔を", "追っていたんだ", 0.2f, 20, 100, 50, font);

            // Transition
            generateCentreRectangleTransition(36964, 37657, blueColor);
            generateCentreRectangleTransition(37426, 37888, blueMarineColor);
        }
        private void ParticleGen(int duration, int StartTime, int EndTime, string LayerName, Vector2 StartPosition, Vector2 EndPosition)
        {
            if (StartTime == EndTime)
            {
                StartTime = (int)Beatmap.HitObjects.First().StartTime;
                EndTime   = (int)Beatmap.HitObjects.Last().EndTime;
            }
            EndTime   = Math.Min(EndTime, (int)AudioDuration);
            StartTime = Math.Min(StartTime, EndTime);

            // This is an example of using a particle pool.
            // Sprites using the same layer, path and origin can be reused as if they were multiple sprites.

            var pos       = new Dictionary <OsbSprite, Vector2d>();
            var connected = new Dictionary <int, List <OsbSprite> >();

            var layer = GetLayer(LayerName);

            using (var pool = new OsbSpritePool(layer, ParticlePath, ParticleOrigin, (particle, startTime, endTime) =>
                                                { }))
            {
                for (int i = StartTime; i < (EndTime); i += TimeBetweenParticles)
                {
                    var Amount       = duration;
                    var ParticleFade = RandomParticleFade ? Random(ParticleFadeMin, ParticleFadeMax) : ParticleFadeMin;
                    var particle     = pool.Get(i, i + Amount);

                    particle.Color(i, ParticleColor);

                    if (StartScale == EndScale && StartScale != 1)
                    {
                        particle.Scale(i, StartScale);
                    }

                    if (StartRotation == EndRotation && StartRotation != 0)
                    {
                        particle.Rotate(i, MathHelper.DegreesToRadians(StartRotation));
                    }

                    if (StartScale != EndScale)
                    {
                        if (RandomScale)
                        {
                            particle.Scale(i, i + Amount, Random(StartScale, EndScale), Random(StartScale, EndScale));
                        }
                        else
                        {
                            particle.Scale(i, i + Amount, StartScale, EndScale);
                        }
                    }

                    if (StartRotation != EndRotation)
                    {
                        if (RandomRotation)
                        {
                            particle.Rotate(i, i + Amount, MathHelper.DegreesToRadians(Random(StartRotation, EndRotation)), MathHelper.DegreesToRadians(Random(StartRotation, EndRotation)));
                        }
                        else
                        {
                            particle.Rotate(i, i + Amount, MathHelper.DegreesToRadians(StartRotation), MathHelper.DegreesToRadians(EndRotation));
                        }
                    }

                    if (ParticleAdditive)
                    {
                        particle.Additive(i, i + Amount);
                    }

                    if (!RandomMovement)
                    {
                        var startX = RandomX ? Random(StartPosition.X, EndPosition.X) : StartPosition.X;
                        var startY = RandomY ? Random(EndPosition.Y, StartPosition.Y) : StartPosition.Y;
                        var endX   = RandomX ? startX : EndPosition.X;
                        var endY   = RandomY ? startY : EndPosition.Y;
                        particle.Move(i, i + Amount, startX, startY, endX, endY);
                    }

                    else
                    {
                        var lastX = Random(StartPosition.X, EndPosition.X);
                        var lastY = Random(StartPosition.Y, EndPosition.Y);

                        var UpdateRate   = 500;
                        var lastAngle    = 0d;
                        var lastDistance = 0d;

                        var rVec = MathHelper.DegreesToRadians(Random(0, 360));
                        var sVec = Random(1, 16);
                        var vX   = (Math.Cos(rVec) * sVec) / (TravelSpeed / 2);
                        var vY   = (Math.Sin(rVec) * sVec) / (TravelSpeed / 2);

                        var startPosition = new Vector2d(lastX, lastY);
                        pos[particle] = startPosition;
                        var endPosition = new Vector2d(lastX, lastY);

                        for (var t = i; t < i + Amount; t += UpdateRate)
                        {
                            var nextX = lastX + (vX / 10);
                            var nextY = lastY + (vY / 10);

                            startPosition.X = lastX;
                            startPosition.Y = lastY;

                            particle.Move(t, t + UpdateRate, lastX, lastY, nextX, nextY);

                            vX += Random(-TravelSpeed, TravelSpeed) * UpdateRate / 1000;
                            vY += Random(-TravelSpeed, TravelSpeed) * UpdateRate / 1000;

                            lastX = nextX;
                            lastY = nextY;
                        }
                    }

                    if (i < EndTime - (FadeTimeIn + FadeTimeOut))
                    {
                        particle.Fade(i, i + FadeTimeIn, 0, ParticleFade);
                        if (i < EndTime - Amount)
                        {
                            particle.Fade(i + Amount - FadeTimeOut, i + Amount, ParticleFade, 0);
                        }
                        else
                        {
                            particle.Fade(EndTime - FadeTimeOut, EndTime, ParticleFade, 0);
                        }
                    }
                    else
                    {
                        particle.Fade(i, 0);
                    }
                }
            }
        }
Exemple #21
0
        public override void Generate()
        {
            if (StartTime == EndTime)
            {
                StartTime = (int)Beatmap.HitObjects.First().StartTime;
                EndTime   = (int)Beatmap.HitObjects.Last().EndTime;
            }
            EndTime   = Math.Min(EndTime, (int)AudioDuration);
            StartTime = Math.Min(StartTime, EndTime);

            var particleDuration = ParticleDuration > 0 ? ParticleDuration :
                                   Beatmap.GetTimingPointAt(StartTime).BeatDuration * 4;

            // This is an example of using a sprite pool.
            // Sprites using the same layer, path and origin can be reused as if they were multiple sprites.

            var layer = GetLayer("");

            using (var pool = new OsbSpritePool(layer, Path, Origin, (sprite, startTime, endTime) =>
            {
                // This action runs for every sprite created from the pool, after all of them are created (AFTER the for loop below).

                // It is intended to set states common to every sprite:
                // In this example, this handles cases where all sprites will have the same color / opacity / scale / rotation / additive mode.

                // Note that the pool is in a using block, this is necessary to run this action.

                if (Color.R < 1 || Color.G < 1 || Color.B < 1)
                {
                    sprite.Color(startTime, Color);
                }

                if (Color.A < 1)
                {
                    sprite.Fade(startTime, Color.A);
                }

                if (StartScale == EndScale && StartScale != 1)
                {
                    sprite.Scale(startTime, StartScale);
                }

                if (StartRotation == EndRotation && StartRotation != 0)
                {
                    sprite.Rotate(startTime, MathHelper.DegreesToRadians(StartRotation));
                }

                if (Additive)
                {
                    sprite.Additive(startTime, endTime);
                }
            }))
            {
                pool.MaxPoolDuration = 0;
                var timeStep = particleDuration / ParticleAmount;
                for (var startTime = (double)StartTime; startTime <= EndTime - particleDuration; startTime += timeStep)
                {
                    var endTime = startTime + particleDuration;

                    // This is where sprites are created from the pool.
                    // Commands here are specific to each sprite.

                    // Note that you must know for how long you are going to use the sprite:
                    // startTime being the start time of the earliest command, endTime the end time of the last command.

                    // Sprites must also be created in order (startTime keeps increasing in each loop iteration),
                    // or sprites won't be properly reused.
                    var sprite = pool.Get(startTime, endTime);

                    var timingPoint  = Beatmap.GetTimingPointAt((int)startTime);
                    var nextBeatTime = timingPoint.Offset;
                    var beatDuration = timingPoint.BeatDuration;

                    while (nextBeatTime < startTime - beatDuration)
                    {
                        nextBeatTime += beatDuration;
                    }

                    double initialRotation = 0;
                    int    whiteTickNumber = (int)Math.Round((nextBeatTime - timingPoint.Offset) / beatDuration);

                    Log($"whitetick:{whiteTickNumber}, startTime: {nextBeatTime}");
                    if (whiteTickNumber % 2 > 0)
                    {
                        initialRotation = Math.PI / 4;
                    }

                    sprite.StartLoopGroup(nextBeatTime, (int)Math.Ceiling((endTime - nextBeatTime) / 952));
                    sprite.Rotate(0, initialRotation);
                    sprite.Rotate(376, 476, initialRotation, initialRotation + Math.PI / 4);
                    sprite.Rotate(852, 952, initialRotation + Math.PI / 4, initialRotation + Math.PI / 2);
                    sprite.EndGroup();

                    var easing = RandomEasing ? (OsbEasing)Random(1, 3) : Easing;

                    var startX = RandomX ? Random(StartPosition.X, EndPosition.X) : StartPosition.X;
                    var startY = RandomY ? Random(StartPosition.Y, EndPosition.Y) : StartPosition.Y;
                    var endX   = RandomX ? startX : EndPosition.X;
                    var endY   = RandomY ? startY : EndPosition.Y;
                    sprite.Move(easing, startTime, endTime, startX, startY, endX, endY);


                    if (FadeInDuration > 0 || FadeOutDuration > 0)
                    {
                        var fadeInTime  = startTime + FadeInDuration;
                        var fadeOutTime = endTime - FadeOutDuration;
                        if (fadeOutTime < fadeInTime)
                        {
                            fadeInTime = fadeOutTime = (fadeInTime + fadeOutTime) / 2;
                        }

                        sprite.Fade(easing, startTime, Math.Max(startTime, fadeInTime), 0, Color.A);
                        sprite.Fade(easing, Math.Min(fadeOutTime, endTime), endTime, Color.A, 0);
                    }

                    if (StartScale != EndScale)
                    {
                        if (RandomScale)
                        {
                            sprite.Scale(easing, startTime, endTime, Random(StartScale, EndScale), Random(StartScale, EndScale));
                        }
                        else
                        {
                            sprite.Scale(easing, startTime, endTime, StartScale, EndScale);
                        }
                    }

                    if (StartRotation != EndRotation)
                    {
                        if (RandomRotation)
                        {
                            sprite.Rotate(easing, startTime, endTime, MathHelper.DegreesToRadians(Random(StartRotation, EndRotation)), MathHelper.DegreesToRadians(Random(StartRotation, EndRotation)));
                        }
                        else
                        {
                            sprite.Rotate(easing, startTime, endTime, MathHelper.DegreesToRadians(StartRotation), MathHelper.DegreesToRadians(EndRotation));
                        }
                    }
                }
            }
        }
Exemple #22
0
        private void ParticleGen(int StartTime, int EndTime, StoryboardLayer layer)
        {
            if (StartTime == EndTime)
            {
                StartTime = (int)Beatmap.HitObjects.First().StartTime;
                EndTime   = (int)Beatmap.HitObjects.Last().EndTime;
            }
            EndTime   = Math.Min(EndTime, (int)AudioDuration);
            StartTime = Math.Min(StartTime, EndTime);

            var pos = new Dictionary <OsbSprite, Vector2d>();

            var MinTravelTime   = 10000;
            var MaxTravelTime   = 20000;
            var ParticleFadeMin = 0.1;
            var ParticleFadeMax = 0.5;

            using (var pool = new OsbSpritePool(layer, "sb/particle3.png", OsbOrigin.Centre, (particle, startTime, endTime) =>
                                                { }))
            {
                bool RandomTravelTime   = true;
                bool RandomParticleFade = true;
                for (int i = StartTime; i < (EndTime); i += 400)
                {
                    var RealTravelTime = RandomTravelTime ? Random(MinTravelTime, MaxTravelTime) : MinTravelTime;
                    var ParticleFade   = RandomParticleFade ? Random(ParticleFadeMin, ParticleFadeMax) : ParticleFadeMin;
                    var particle       = pool.Get(i, i + RealTravelTime);

                    particle.Color(i, ParticleColor);
                    particle.Additive(i, i + RealTravelTime);

                    if (layer == GetLayer("Front"))
                    {
                        var StartScale = Random(0.05, 0.1);
                        var EndScale   = Random(0.05, 0.1);
                        if (StartScale == EndScale && StartScale != 1)
                        {
                            particle.Scale(i, StartScale);
                        }

                        bool RandomScale = true;
                        if (StartScale != EndScale)
                        {
                            if (RandomScale)
                            {
                                particle.Scale(i, i + RealTravelTime, Random(StartScale, EndScale), Random(StartScale, EndScale));
                            }
                            else
                            {
                                particle.Scale(i, i + RealTravelTime, StartScale, EndScale);
                            }
                        }
                    }

                    else
                    {
                        var StartScale = Random(0.02, 0.05);
                        var EndScale   = Random(0.02, 0.05);
                        if (StartScale == EndScale && StartScale != 1)
                        {
                            particle.Scale(i, StartScale);
                        }

                        bool RandomScale = true;
                        if (StartScale != EndScale)
                        {
                            if (RandomScale)
                            {
                                particle.Scale(i, i + RealTravelTime, Random(StartScale, EndScale), Random(StartScale, EndScale));
                            }
                            else
                            {
                                particle.Scale(i, i + RealTravelTime, StartScale, EndScale);
                            }
                        }
                    }

                    bool RandomMovement = true;
                    bool RandomX        = true;
                    bool RandomY        = true;

                    var StartPosition = new Vector2(-107, 0);
                    var EndPosition   = new Vector2(747, 480);
                    if (!RandomMovement)
                    {
                        var startX = RandomX ? Random(StartPosition.X, EndPosition.X) : StartPosition.X;
                        var startY = RandomY ? Random(EndPosition.Y, StartPosition.Y) : StartPosition.Y;
                        var endX   = RandomX ? startX : EndPosition.X;
                        var endY   = RandomY ? startY : EndPosition.Y;
                        particle.Move(i, i + RealTravelTime, startX, startY, endX, endY);
                    }

                    else
                    {
                        var lastX = Random(StartPosition.X, EndPosition.X);
                        var lastY = Random(StartPosition.Y, EndPosition.Y);

                        var UpdateRate = 500;
                        // var lastAngle = 0d;
                        // var lastDistance = 0d;

                        var TravelSpeed = 50;
                        var rVec        = MathHelper.DegreesToRadians(Random(0, 360));
                        var sVec        = Random(1, 16);
                        var vX          = (Math.Cos(rVec) * sVec) / (TravelSpeed / 2);
                        var vY          = (Math.Sin(rVec) * sVec) / (TravelSpeed / 2);

                        var startPosition = new Vector2d(lastX, lastY);
                        pos[particle] = startPosition;
                        var endPosition = new Vector2d(lastX, lastY);

                        for (var t = i; t < i + RealTravelTime; t += UpdateRate)
                        {
                            var nextX = lastX + (vX / 10);
                            var nextY = lastY + (vY / 10);

                            startPosition.X = lastX;
                            startPosition.Y = lastY;

                            particle.Move(t, t + UpdateRate, lastX, lastY, nextX, nextY);

                            vX += Random(-TravelSpeed, TravelSpeed) * UpdateRate / 1000;
                            vY += Random(-TravelSpeed, TravelSpeed) * UpdateRate / 1000;

                            lastX = nextX;
                            lastY = nextY;
                        }
                    }

                    var FadeTimeIn  = 1000;
                    var FadeTimeOut = 1000;
                    if (i < EndTime - (FadeTimeIn + FadeTimeOut))
                    {
                        particle.Fade(i, i + FadeTimeIn, 0, ParticleFade);
                        if (i < EndTime - RealTravelTime)
                        {
                            particle.Fade(i + RealTravelTime - FadeTimeOut, i + RealTravelTime, ParticleFade, 0);
                        }
                        else
                        {
                            particle.Fade(EndTime - FadeTimeOut, EndTime, ParticleFade, 0);
                        }
                    }
                    else
                    {
                        particle.Fade(i, 0);
                    }
                }
            }
        }