1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:47:26 +08:00

Randomise direction every animation playback

This commit is contained in:
Dean Herbert 2020-11-19 15:55:11 +09:00
parent 9d04ce75cc
commit efd5acb8ab

View File

@ -20,7 +20,7 @@ namespace osu.Game.Graphics
{ {
double rDuration = RNG.NextDouble(duration / 3, duration); double rDuration = RNG.NextDouble(duration / 3, duration);
AddInternal(new Particle(rDuration, RNG.NextSingle(0, MathF.PI * 2)) AddInternal(new Particle(rDuration)
{ {
Texture = texture Texture = texture
}); });
@ -36,19 +36,12 @@ namespace osu.Game.Graphics
private class Particle : Sprite private class Particle : Sprite
{ {
private readonly double duration; private readonly double duration;
private readonly float direction;
public override bool RemoveWhenNotAlive => false; public override bool RemoveWhenNotAlive => false;
private Vector2 positionForOffset(float offset) => new Vector2( public Particle(double duration)
(float)(offset * Math.Sin(direction)),
(float)(offset * Math.Cos(direction))
);
public Particle(double duration, float direction)
{ {
this.duration = duration; this.duration = duration;
this.direction = direction;
Origin = Anchor.Centre; Origin = Anchor.Centre;
Blending = BlendingParameters.Additive; Blending = BlendingParameters.Additive;
@ -64,11 +57,18 @@ namespace osu.Game.Graphics
public void Play() public void Play()
{ {
double direction = RNG.NextSingle(0, MathF.PI * 2);
this.MoveTo(new Vector2(0.5f)); this.MoveTo(new Vector2(0.5f));
this.MoveTo(new Vector2(0.5f) + positionForOffset(0.5f), duration); this.MoveTo(new Vector2(0.5f) + positionForOffset(0.5f), duration);
this.FadeOutFromOne(duration); this.FadeOutFromOne(duration);
Expire(); Expire();
Vector2 positionForOffset(float offset) => new Vector2(
(float)(offset * Math.Sin(direction)),
(float)(offset * Math.Cos(direction))
);
} }
} }
} }