mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 16:12:54 +08:00
Compute object position in stack via a pure function
This commit is contained in:
parent
0739f09930
commit
56721a6fa9
@ -447,8 +447,10 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
|
|
||||||
if (caughtObject == null) return;
|
if (caughtObject == null) return;
|
||||||
|
|
||||||
|
var positionInStack = computePositionInStack(new Vector2(source.X - X, 0), caughtObject.DisplayRadius);
|
||||||
|
|
||||||
caughtObject.RelativePositionAxes = Axes.None;
|
caughtObject.RelativePositionAxes = Axes.None;
|
||||||
caughtObject.X = source.X - X;
|
caughtObject.Position = positionInStack;
|
||||||
caughtObject.IsOnPlate = true;
|
caughtObject.IsOnPlate = true;
|
||||||
|
|
||||||
caughtObject.Anchor = Anchor.TopCentre;
|
caughtObject.Anchor = Anchor.TopCentre;
|
||||||
@ -457,8 +459,6 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
caughtObject.LifetimeStart = source.StartTime;
|
caughtObject.LifetimeStart = source.StartTime;
|
||||||
caughtObject.LifetimeEnd = double.MaxValue;
|
caughtObject.LifetimeEnd = double.MaxValue;
|
||||||
|
|
||||||
adjustPositionInStack(caughtObject);
|
|
||||||
|
|
||||||
caughtFruitContainer.Add(caughtObject);
|
caughtFruitContainer.Add(caughtObject);
|
||||||
|
|
||||||
addLighting(caughtObject);
|
addLighting(caughtObject);
|
||||||
@ -467,22 +467,22 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
removeFromPlate(caughtObject, DroppedObjectAnimation.Explode);
|
removeFromPlate(caughtObject, DroppedObjectAnimation.Explode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void adjustPositionInStack(DrawablePalpableCatchHitObject caughtObject)
|
private Vector2 computePositionInStack(Vector2 position, float displayRadius)
|
||||||
{
|
{
|
||||||
const float radius_div_2 = CatchHitObject.OBJECT_RADIUS / 2;
|
const float radius_div_2 = CatchHitObject.OBJECT_RADIUS / 2;
|
||||||
const float allowance = 10;
|
const float allowance = 10;
|
||||||
|
|
||||||
float caughtObjectRadius = caughtObject.DisplayRadius;
|
while (caughtFruitContainer.Any(f => Vector2Extensions.Distance(f.Position, position) < (displayRadius + radius_div_2) / (allowance / 2)))
|
||||||
|
|
||||||
while (caughtFruitContainer.Any(f => Vector2Extensions.Distance(f.Position, caughtObject.Position) < (caughtObjectRadius + radius_div_2) / (allowance / 2)))
|
|
||||||
{
|
{
|
||||||
float diff = (caughtObjectRadius + radius_div_2) / allowance;
|
float diff = (displayRadius + radius_div_2) / allowance;
|
||||||
|
|
||||||
caughtObject.X += (RNG.NextSingle() - 0.5f) * diff * 2;
|
position.X += (RNG.NextSingle() - 0.5f) * diff * 2;
|
||||||
caughtObject.Y -= RNG.NextSingle() * diff;
|
position.Y -= RNG.NextSingle() * diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
caughtObject.X = Math.Clamp(caughtObject.X, -CatcherArea.CATCHER_SIZE / 2, CatcherArea.CATCHER_SIZE / 2);
|
position.X = Math.Clamp(position.X, -CatcherArea.CATCHER_SIZE / 2, CatcherArea.CATCHER_SIZE / 2);
|
||||||
|
|
||||||
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addLighting(DrawablePalpableCatchHitObject caughtObject)
|
private void addLighting(DrawablePalpableCatchHitObject caughtObject)
|
||||||
|
Loading…
Reference in New Issue
Block a user