1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 06:52:55 +08:00

Further code tidying

This commit is contained in:
Dean Herbert 2018-09-14 18:18:40 +09:00
parent 00daaef27a
commit ef31698f56

View File

@ -7,6 +7,7 @@ using osu.Framework.Graphics;
using osu.Game.Graphics;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Objects;
using OpenTK;
@ -21,7 +22,7 @@ namespace osu.Game.Rulesets.Osu.Mods
public override string Description => "They just won't stay still...";
public override double ScoreMultiplier => 1;
private const int wiggle_delay = 90; // (ms) Higher = fewer wiggles
private const int wiggle_duration = 90; // (ms) Higher = fewer wiggles
private const int wiggle_strength = 10; // Higher = stronger wiggles
public void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables)
@ -32,51 +33,35 @@ namespace osu.Game.Rulesets.Osu.Mods
private void drawableOnApplyCustomUpdateState(DrawableHitObject drawable, ArmedState state)
{
var hitObject = (OsuHitObject)drawable.HitObject;
Vector2 origPos = drawable.Position;
var osuObject = (OsuHitObject)drawable.HitObject;
Vector2 origin = drawable.Position;
Random distRand = new Random(hitObject.ComboOffset);
Random angleRand = new Random(hitObject.IndexInCurrentCombo);
Random distRand = new Random(osuObject.ComboOffset);
Random angleRand = new Random(osuObject.IndexInCurrentCombo);
// Wiggle all objects during TimePreempt
int amountWiggles = (int)hitObject.TimePreempt / wiggle_delay;
int amountWiggles = (int)osuObject.TimePreempt / wiggle_duration;
void wiggle()
{
float nextAngle = (float)(angleRand.NextDouble() * 2 * Math.PI);
float nextDist = (float)(distRand.NextDouble() * wiggle_strength);
drawable.MoveTo(new Vector2((float)(nextDist * Math.Cos(nextAngle) + origin.X), (float)(nextDist * Math.Sin(nextAngle) + origin.Y)), wiggle_duration);
}
for (int i = 0; i < amountWiggles; i++)
{
using (drawable.BeginAbsoluteSequence(hitObject.StartTime - hitObject.TimePreempt + i * wiggle_delay, true))
{
float nextAngle = (float)(angleRand.NextDouble() * 2 * Math.PI);
float nextDist = (float)(distRand.NextDouble() * wiggle_strength);
Vector2 wiggledPos = new Vector2((float)(nextDist * Math.Cos(nextAngle) + origPos.X), (float)(nextDist * Math.Sin(nextAngle) + origPos.Y));
drawable.MoveTo(wiggledPos, wiggle_delay);
}
}
using (drawable.BeginAbsoluteSequence(osuObject.StartTime - osuObject.TimePreempt + i * wiggle_duration, true))
wiggle();
// Keep wiggling sliders and spinners for their duration
double objDuration;
if (hitObject is Slider slider)
{
objDuration = slider.Duration;
}
else if (hitObject is Spinner spinner)
{
objDuration = spinner.Duration;
}
else
if (!(osuObject is IHasEndTime endTime))
return;
amountWiggles = (int)(objDuration / wiggle_delay);
amountWiggles = (int)(endTime.Duration / wiggle_duration);
for (int i = 0; i < amountWiggles; i++)
{
using (drawable.BeginAbsoluteSequence(hitObject.StartTime + i * wiggle_delay, true))
{
float nextAngle = (float)(angleRand.NextDouble() * 2 * Math.PI);
float nextDist = (float)(distRand.NextDouble() * wiggle_strength);
Vector2 wiggledPos = new Vector2((float)(nextDist * Math.Cos(nextAngle) + origPos.X), (float)(nextDist * Math.Sin(nextAngle) + origPos.Y));
drawable.MoveTo(wiggledPos, wiggle_delay);
}
}
using (drawable.BeginAbsoluteSequence(osuObject.StartTime + i * wiggle_duration, true))
wiggle();
}
}
}