mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 16:42:57 +08:00
Add cursor velocity to star particles
This commit is contained in:
parent
ee4006f3d7
commit
5b1b36436f
@ -131,6 +131,44 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
|||||||
public StarParticleSpewer(Texture texture, int perSecond)
|
public StarParticleSpewer(Texture texture, int perSecond)
|
||||||
: base(texture, perSecond, particle_lifetime_max)
|
: base(texture, perSecond, particle_lifetime_max)
|
||||||
{
|
{
|
||||||
|
Active.BindValueChanged(_ => resetVelocityCalculation());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vector2 screenPosition => ToScreenSpace(OriginPosition);
|
||||||
|
|
||||||
|
private Vector2 screenVelocity;
|
||||||
|
|
||||||
|
private const double velocity_calculation_delay = 15;
|
||||||
|
private double lastVelocityCalculation;
|
||||||
|
private Vector2 positionDifference;
|
||||||
|
private Vector2? lastPosition;
|
||||||
|
|
||||||
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
|
||||||
|
if (lastPosition != null)
|
||||||
|
{
|
||||||
|
positionDifference += (screenPosition - lastPosition.Value);
|
||||||
|
lastVelocityCalculation += Clock.ElapsedFrameTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastPosition = screenPosition;
|
||||||
|
|
||||||
|
if (lastVelocityCalculation > velocity_calculation_delay)
|
||||||
|
{
|
||||||
|
screenVelocity = positionDifference / (float)lastVelocityCalculation;
|
||||||
|
|
||||||
|
positionDifference = Vector2.Zero;
|
||||||
|
lastVelocityCalculation = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetVelocityCalculation()
|
||||||
|
{
|
||||||
|
positionDifference = Vector2.Zero;
|
||||||
|
lastVelocityCalculation = 0;
|
||||||
|
lastPosition = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override FallingParticle SpawnParticle()
|
protected override FallingParticle SpawnParticle()
|
||||||
@ -170,6 +208,8 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.Velocity += screenVelocity * 50;
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user