2020-03-13 11:59:30 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Linq;
|
2020-04-22 10:04:07 +08:00
|
|
|
using JetBrains.Annotations;
|
2020-03-13 11:59:30 +08:00
|
|
|
using osu.Framework.Allocation;
|
2020-07-14 11:52:34 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-03-13 11:59:30 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Animations;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-12-01 10:32:20 +08:00
|
|
|
using osu.Framework.Graphics.Pooling;
|
2020-03-13 11:59:30 +08:00
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
using osu.Framework.Utils;
|
|
|
|
using osu.Game.Beatmaps;
|
2020-07-14 11:35:01 +08:00
|
|
|
using osu.Game.Configuration;
|
2020-12-08 14:02:55 +08:00
|
|
|
using osu.Game.Rulesets.Catch.Judgements;
|
2020-03-13 11:59:30 +08:00
|
|
|
using osu.Game.Rulesets.Catch.Objects;
|
|
|
|
using osu.Game.Rulesets.Catch.Objects.Drawables;
|
2020-03-26 14:11:59 +08:00
|
|
|
using osu.Game.Rulesets.Catch.Skinning;
|
2020-12-08 13:28:30 +08:00
|
|
|
using osu.Game.Rulesets.Judgements;
|
2020-03-26 14:11:59 +08:00
|
|
|
using osu.Game.Skinning;
|
2020-03-13 11:59:30 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.UI
|
|
|
|
{
|
2020-03-26 14:11:59 +08:00
|
|
|
public class Catcher : SkinReloadableDrawable, IKeyBindingHandler<CatchAction>
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
2020-04-21 16:36:09 +08:00
|
|
|
/// <summary>
|
2020-05-07 05:27:01 +08:00
|
|
|
/// The default colour used to tint hyper-dash fruit, along with the moving catcher, its trail
|
|
|
|
/// and end glow/after-image during a hyper-dash.
|
2020-04-21 16:36:09 +08:00
|
|
|
/// </summary>
|
2020-04-08 19:23:29 +08:00
|
|
|
public static readonly Color4 DEFAULT_HYPER_DASH_COLOUR = Color4.Red;
|
2020-03-26 10:37:26 +08:00
|
|
|
|
2020-04-22 10:12:29 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The duration between transitioning to hyper-dash state.
|
|
|
|
/// </summary>
|
|
|
|
public const double HYPER_DASH_TRANSITION_DURATION = 180;
|
|
|
|
|
2020-03-13 11:59:30 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether we are hyper-dashing or not.
|
|
|
|
/// </summary>
|
|
|
|
public bool HyperDashing => hyperDashModifier != 1;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The relative space to cover in 1 millisecond. based on 1 game pixel per millisecond as in osu-stable.
|
|
|
|
/// </summary>
|
2020-07-01 23:21:45 +08:00
|
|
|
public const double BASE_SPEED = 1.0;
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-04-22 10:12:29 +08:00
|
|
|
[NotNull]
|
|
|
|
private readonly Container trailsTarget;
|
|
|
|
|
|
|
|
private CatcherTrailDisplay trails;
|
2020-03-26 14:11:31 +08:00
|
|
|
|
2020-12-02 20:23:34 +08:00
|
|
|
private readonly Container droppedObjectTarget;
|
|
|
|
|
2020-12-08 19:34:08 +08:00
|
|
|
private readonly Container<CaughtObject> caughtFruitContainer;
|
2020-12-02 20:23:34 +08:00
|
|
|
|
2020-03-13 11:59:30 +08:00
|
|
|
public CatcherAnimationState CurrentState { get; private set; }
|
|
|
|
|
2020-03-31 17:33:00 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The width of the catcher which can receive fruit. Equivalent to "catchMargin" in osu-stable.
|
|
|
|
/// </summary>
|
2020-08-21 01:21:16 +08:00
|
|
|
public const float ALLOWED_CATCH_RANGE = 0.8f;
|
2020-03-31 17:33:00 +08:00
|
|
|
|
2020-04-22 10:12:29 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The drawable catcher for <see cref="CurrentState"/>.
|
|
|
|
/// </summary>
|
|
|
|
internal Drawable CurrentDrawableCatcher => currentCatcher.Drawable;
|
|
|
|
|
|
|
|
private bool dashing;
|
|
|
|
|
|
|
|
public bool Dashing
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
|
|
|
get => dashing;
|
2020-04-22 10:12:29 +08:00
|
|
|
protected set
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
|
|
|
if (value == dashing) return;
|
|
|
|
|
|
|
|
dashing = value;
|
|
|
|
|
2020-05-10 23:05:30 +08:00
|
|
|
updateTrailVisibility();
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 12:27:15 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Width of the area that can be used to attempt catches during gameplay.
|
|
|
|
/// </summary>
|
|
|
|
private readonly float catchWidth;
|
|
|
|
|
2020-12-02 18:28:47 +08:00
|
|
|
private readonly CatcherSprite catcherIdle;
|
|
|
|
private readonly CatcherSprite catcherKiai;
|
|
|
|
private readonly CatcherSprite catcherFail;
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-03-14 16:06:23 +08:00
|
|
|
private CatcherSprite currentCatcher;
|
|
|
|
|
2020-04-21 10:58:56 +08:00
|
|
|
private Color4 hyperDashColour = DEFAULT_HYPER_DASH_COLOUR;
|
|
|
|
private Color4 hyperDashEndGlowColour = DEFAULT_HYPER_DASH_COLOUR;
|
2020-03-26 14:11:31 +08:00
|
|
|
|
2020-03-13 11:59:30 +08:00
|
|
|
private int currentDirection;
|
|
|
|
|
|
|
|
private double hyperDashModifier = 1;
|
|
|
|
private int hyperDashDirection;
|
|
|
|
private float hyperDashTargetPosition;
|
2020-07-14 11:52:34 +08:00
|
|
|
private Bindable<bool> hitLighting;
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-02 18:28:47 +08:00
|
|
|
private readonly DrawablePool<HitExplosion> hitExplosionPool;
|
|
|
|
private readonly Container<HitExplosion> hitExplosionContainer;
|
2020-12-01 10:32:20 +08:00
|
|
|
|
2020-12-08 21:38:10 +08:00
|
|
|
private readonly DrawablePool<CaughtFruit> caughtFruitPool;
|
|
|
|
private readonly DrawablePool<CaughtBanana> caughtBananaPool;
|
|
|
|
private readonly DrawablePool<CaughtDroplet> caughtDropletPool;
|
|
|
|
|
2020-12-02 20:23:34 +08:00
|
|
|
public Catcher([NotNull] Container trailsTarget, [NotNull] Container droppedObjectTarget, BeatmapDifficulty difficulty = null)
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
2020-04-22 10:12:29 +08:00
|
|
|
this.trailsTarget = trailsTarget;
|
2020-12-02 20:23:34 +08:00
|
|
|
this.droppedObjectTarget = droppedObjectTarget;
|
2020-04-21 16:41:53 +08:00
|
|
|
|
2020-03-13 11:59:30 +08:00
|
|
|
Origin = Anchor.TopCentre;
|
|
|
|
|
|
|
|
Size = new Vector2(CatcherArea.CATCHER_SIZE);
|
|
|
|
if (difficulty != null)
|
2020-04-22 12:37:49 +08:00
|
|
|
Scale = calculateScale(difficulty);
|
2020-04-22 12:27:15 +08:00
|
|
|
|
|
|
|
catchWidth = CalculateCatchWidth(Scale);
|
2020-07-14 11:35:01 +08:00
|
|
|
|
2020-03-26 14:11:59 +08:00
|
|
|
InternalChildren = new Drawable[]
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
2020-12-01 10:32:20 +08:00
|
|
|
hitExplosionPool = new DrawablePool<HitExplosion>(10),
|
2020-12-08 21:38:10 +08:00
|
|
|
caughtFruitPool = new DrawablePool<CaughtFruit>(50),
|
|
|
|
caughtBananaPool = new DrawablePool<CaughtBanana>(100),
|
|
|
|
// less capacity is needed compared to fruit because droplet is not stacked
|
|
|
|
caughtDropletPool = new DrawablePool<CaughtDroplet>(25),
|
2020-12-08 19:34:08 +08:00
|
|
|
caughtFruitContainer = new Container<CaughtObject>
|
2020-12-02 18:28:47 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
},
|
2020-03-13 11:59:30 +08:00
|
|
|
catcherIdle = new CatcherSprite(CatcherAnimationState.Idle)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Alpha = 0,
|
|
|
|
},
|
|
|
|
catcherKiai = new CatcherSprite(CatcherAnimationState.Kiai)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Alpha = 0,
|
|
|
|
},
|
|
|
|
catcherFail = new CatcherSprite(CatcherAnimationState.Fail)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Alpha = 0,
|
2020-12-01 10:32:20 +08:00
|
|
|
},
|
|
|
|
hitExplosionContainer = new Container<HitExplosion>
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
},
|
2020-03-13 11:59:30 +08:00
|
|
|
};
|
2020-12-02 18:28:47 +08:00
|
|
|
}
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-02 18:28:47 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
{
|
|
|
|
hitLighting = config.GetBindable<bool>(OsuSetting.HitLighting);
|
2020-10-19 16:41:21 +08:00
|
|
|
trails = new CatcherTrailDisplay(this);
|
2020-04-21 16:41:53 +08:00
|
|
|
|
|
|
|
updateCatcher();
|
2020-04-05 00:33:52 +08:00
|
|
|
}
|
|
|
|
|
2020-10-19 16:41:21 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
// don't add in above load as we may potentially modify a parent in an unsafe manner.
|
|
|
|
trailsTarget.Add(trails);
|
|
|
|
}
|
|
|
|
|
2020-07-16 14:35:19 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Creates proxied content to be displayed beneath hitobjects.
|
|
|
|
/// </summary>
|
|
|
|
public Drawable CreateProxiedContent() => caughtFruitContainer.CreateProxy();
|
|
|
|
|
2020-04-22 12:27:15 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Calculates the scale of the catcher based off the provided beatmap difficulty.
|
|
|
|
/// </summary>
|
2020-12-04 13:35:56 +08:00
|
|
|
private static Vector2 calculateScale(BeatmapDifficulty difficulty) => new Vector2(1.0f - 0.7f * (difficulty.CircleSize - 5) / 5);
|
2020-04-22 12:27:15 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Calculates the width of the area used for attempting catches in gameplay.
|
|
|
|
/// </summary>
|
2020-04-22 12:36:59 +08:00
|
|
|
/// <param name="scale">The scale of the catcher.</param>
|
2020-12-04 13:35:56 +08:00
|
|
|
internal static float CalculateCatchWidth(Vector2 scale) => CatcherArea.CATCHER_SIZE * Math.Abs(scale.X) * ALLOWED_CATCH_RANGE;
|
2020-04-22 12:27:15 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Calculates the width of the area used for attempting catches in gameplay.
|
|
|
|
/// </summary>
|
2020-04-22 12:36:59 +08:00
|
|
|
/// <param name="difficulty">The beatmap difficulty.</param>
|
2020-12-04 13:35:56 +08:00
|
|
|
internal static float CalculateCatchWidth(BeatmapDifficulty difficulty) => CalculateCatchWidth(calculateScale(difficulty));
|
2020-03-13 11:59:30 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2020-12-08 13:28:30 +08:00
|
|
|
/// Determine if this catcher can catch a <see cref="CatchHitObject"/> in the current position.
|
2020-03-13 11:59:30 +08:00
|
|
|
/// </summary>
|
2020-12-08 13:28:30 +08:00
|
|
|
public bool CanCatch(CatchHitObject hitObject)
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
2020-11-24 18:57:37 +08:00
|
|
|
if (!(hitObject is PalpableCatchHitObject fruit))
|
2020-08-21 00:58:07 +08:00
|
|
|
return false;
|
|
|
|
|
2020-04-22 12:27:15 +08:00
|
|
|
var halfCatchWidth = catchWidth * 0.5f;
|
2020-03-13 11:59:30 +08:00
|
|
|
|
|
|
|
// this stuff wil disappear once we move fruit to non-relative coordinate space in the future.
|
2020-07-01 23:21:45 +08:00
|
|
|
var catchObjectPosition = fruit.X;
|
|
|
|
var catcherPosition = Position.X;
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-08 13:28:30 +08:00
|
|
|
return catchObjectPosition >= catcherPosition - halfCatchWidth &&
|
|
|
|
catchObjectPosition <= catcherPosition + halfCatchWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnNewResult(DrawableCatchHitObject drawableObject, JudgementResult result)
|
|
|
|
{
|
2020-12-08 14:02:55 +08:00
|
|
|
var catchResult = (CatchJudgementResult)result;
|
|
|
|
catchResult.CatcherAnimationState = CurrentState;
|
2020-12-08 14:21:47 +08:00
|
|
|
catchResult.CatcherHyperDash = HyperDashing;
|
2020-12-08 14:02:55 +08:00
|
|
|
|
2020-12-08 20:29:03 +08:00
|
|
|
if (!(drawableObject is DrawablePalpableHasCatchHitObject palpableObject)) return;
|
2020-12-08 19:41:26 +08:00
|
|
|
|
|
|
|
var hitObject = palpableObject.HitObject;
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-08 13:28:30 +08:00
|
|
|
if (result.IsHit)
|
2020-12-08 19:41:26 +08:00
|
|
|
{
|
|
|
|
var positionInStack = computePositionInStack(new Vector2(palpableObject.X - X, 0), palpableObject.DisplayRadius);
|
|
|
|
|
2020-12-08 19:34:08 +08:00
|
|
|
placeCaughtObject(palpableObject, positionInStack);
|
2020-12-08 19:41:26 +08:00
|
|
|
|
|
|
|
if (hitLighting.Value)
|
|
|
|
addLighting(hitObject, positionInStack.X, drawableObject.AccentColour.Value);
|
|
|
|
}
|
2020-12-04 09:24:25 +08:00
|
|
|
|
2020-12-03 13:44:35 +08:00
|
|
|
// droplet doesn't affect the catcher state
|
2020-12-08 13:28:30 +08:00
|
|
|
if (hitObject is TinyDroplet) return;
|
2020-12-04 09:24:25 +08:00
|
|
|
|
2020-12-08 13:28:30 +08:00
|
|
|
if (result.IsHit && hitObject.HyperDash)
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
2020-12-08 13:28:30 +08:00
|
|
|
var target = hitObject.HyperDashTarget;
|
|
|
|
var timeDifference = target.StartTime - hitObject.StartTime;
|
|
|
|
double positionDifference = target.X - X;
|
2020-12-04 09:24:25 +08:00
|
|
|
var velocity = positionDifference / Math.Max(1.0, timeDifference - 1000.0 / 60.0);
|
|
|
|
|
|
|
|
SetHyperDashState(Math.Abs(velocity), target.X);
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|
2020-12-04 09:24:25 +08:00
|
|
|
else
|
|
|
|
SetHyperDashState();
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-08 13:28:30 +08:00
|
|
|
if (result.IsHit)
|
|
|
|
updateState(hitObject.Kiai ? CatcherAnimationState.Kiai : CatcherAnimationState.Idle);
|
|
|
|
else if (!(hitObject is Banana))
|
2020-12-04 09:24:25 +08:00
|
|
|
updateState(CatcherAnimationState.Fail);
|
2020-12-08 13:28:30 +08:00
|
|
|
}
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-08 14:24:39 +08:00
|
|
|
public void OnRevertResult(DrawableCatchHitObject drawableObject, JudgementResult result)
|
2020-12-08 13:28:30 +08:00
|
|
|
{
|
2020-12-08 14:02:55 +08:00
|
|
|
var catchResult = (CatchJudgementResult)result;
|
2020-12-08 14:21:47 +08:00
|
|
|
|
|
|
|
if (CurrentState != catchResult.CatcherAnimationState)
|
|
|
|
updateState(catchResult.CatcherAnimationState);
|
|
|
|
|
|
|
|
if (HyperDashing != catchResult.CatcherHyperDash)
|
|
|
|
{
|
|
|
|
if (catchResult.CatcherHyperDash)
|
|
|
|
SetHyperDashState(2);
|
|
|
|
else
|
|
|
|
SetHyperDashState();
|
|
|
|
}
|
2020-12-08 14:24:39 +08:00
|
|
|
|
|
|
|
caughtFruitContainer.RemoveAll(d => d.HitObject == drawableObject.HitObject);
|
2020-12-08 22:07:30 +08:00
|
|
|
droppedObjectTarget.RemoveAll(d => (d as CaughtObject)?.HitObject == drawableObject.HitObject);
|
2020-12-08 14:43:17 +08:00
|
|
|
hitExplosionContainer.RemoveAll(d => d.HitObject == drawableObject.HitObject);
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set hyper-dash state.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="modifier">The speed multiplier. If this is less or equals to 1, this catcher will be non-hyper-dashing state.</param>
|
|
|
|
/// <param name="targetPosition">When this catcher crosses this position, this catcher ends hyper-dashing.</param>
|
|
|
|
public void SetHyperDashState(double modifier = 1, float targetPosition = -1)
|
|
|
|
{
|
|
|
|
var wasHyperDashing = HyperDashing;
|
|
|
|
|
|
|
|
if (modifier <= 1 || X == targetPosition)
|
|
|
|
{
|
|
|
|
hyperDashModifier = 1;
|
|
|
|
hyperDashDirection = 0;
|
|
|
|
|
|
|
|
if (wasHyperDashing)
|
2020-05-10 23:05:30 +08:00
|
|
|
runHyperDashStateTransition(false);
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hyperDashModifier = modifier;
|
|
|
|
hyperDashDirection = Math.Sign(targetPosition - X);
|
|
|
|
hyperDashTargetPosition = targetPosition;
|
|
|
|
|
|
|
|
if (!wasHyperDashing)
|
|
|
|
{
|
2020-04-22 10:12:29 +08:00
|
|
|
trails.DisplayEndGlow();
|
2020-05-10 23:05:30 +08:00
|
|
|
runHyperDashStateTransition(true);
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|
|
|
|
}
|
2020-03-26 14:11:31 +08:00
|
|
|
}
|
|
|
|
|
2020-12-04 13:36:40 +08:00
|
|
|
public void UpdatePosition(float position)
|
2020-03-26 14:11:31 +08:00
|
|
|
{
|
2020-12-04 13:36:40 +08:00
|
|
|
position = Math.Clamp(position, 0, CatchPlayfield.WIDTH);
|
2020-05-10 23:05:30 +08:00
|
|
|
|
2020-12-04 13:36:40 +08:00
|
|
|
if (position == X)
|
|
|
|
return;
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-04 13:36:40 +08:00
|
|
|
Scale = new Vector2(Math.Abs(Scale.X) * (position > X ? 1 : -1), Scale.Y);
|
|
|
|
X = position;
|
|
|
|
}
|
2020-05-10 23:05:30 +08:00
|
|
|
|
2020-03-13 11:59:30 +08:00
|
|
|
public bool OnPressed(CatchAction action)
|
|
|
|
{
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case CatchAction.MoveLeft:
|
|
|
|
currentDirection--;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case CatchAction.MoveRight:
|
|
|
|
currentDirection++;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case CatchAction.Dash:
|
|
|
|
Dashing = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnReleased(CatchAction action)
|
|
|
|
{
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case CatchAction.MoveLeft:
|
|
|
|
currentDirection++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CatchAction.MoveRight:
|
|
|
|
currentDirection--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CatchAction.Dash:
|
|
|
|
Dashing = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Drop any fruit off the plate.
|
|
|
|
/// </summary>
|
2020-12-02 20:23:34 +08:00
|
|
|
public void Drop() => clearPlate(DroppedObjectAnimation.Drop);
|
2020-03-13 11:59:30 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2020-12-04 13:35:56 +08:00
|
|
|
/// Explode all fruit off the plate.
|
2020-03-13 11:59:30 +08:00
|
|
|
/// </summary>
|
2020-12-02 20:23:34 +08:00
|
|
|
public void Explode() => clearPlate(DroppedObjectAnimation.Explode);
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-04 13:36:40 +08:00
|
|
|
private void runHyperDashStateTransition(bool hyperDashing)
|
|
|
|
{
|
|
|
|
updateTrailVisibility();
|
|
|
|
|
|
|
|
if (hyperDashing)
|
|
|
|
{
|
|
|
|
this.FadeColour(hyperDashColour, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
this.FadeTo(0.2f, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.FadeColour(Color4.White, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
this.FadeTo(1f, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateTrailVisibility() => trails.DisplayTrail = Dashing || HyperDashing;
|
|
|
|
|
2020-03-26 14:11:59 +08:00
|
|
|
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
|
|
|
|
{
|
|
|
|
base.SkinChanged(skin, allowFallback);
|
|
|
|
|
2020-04-21 10:58:56 +08:00
|
|
|
hyperDashColour =
|
|
|
|
skin.GetConfig<CatchSkinColour, Color4>(CatchSkinColour.HyperDash)?.Value ??
|
|
|
|
DEFAULT_HYPER_DASH_COLOUR;
|
|
|
|
|
|
|
|
hyperDashEndGlowColour =
|
|
|
|
skin.GetConfig<CatchSkinColour, Color4>(CatchSkinColour.HyperDashAfterImage)?.Value ??
|
|
|
|
hyperDashColour;
|
|
|
|
|
2020-08-24 21:57:41 +08:00
|
|
|
trails.HyperDashTrailsColour = hyperDashColour;
|
|
|
|
trails.EndGlowSpritesColour = hyperDashEndGlowColour;
|
|
|
|
|
2020-05-10 23:05:30 +08:00
|
|
|
runHyperDashStateTransition(HyperDashing);
|
2020-03-26 14:11:59 +08:00
|
|
|
}
|
|
|
|
|
2020-03-13 11:59:30 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
if (currentDirection == 0) return;
|
|
|
|
|
|
|
|
var direction = Math.Sign(currentDirection);
|
|
|
|
|
|
|
|
var dashModifier = Dashing ? 1 : 0.5;
|
|
|
|
var speed = BASE_SPEED * dashModifier * hyperDashModifier;
|
|
|
|
|
|
|
|
UpdatePosition((float)(X + direction * Clock.ElapsedFrameTime * speed));
|
|
|
|
|
|
|
|
// Correct overshooting.
|
2020-03-14 14:35:59 +08:00
|
|
|
if ((hyperDashDirection > 0 && hyperDashTargetPosition < X) ||
|
|
|
|
(hyperDashDirection < 0 && hyperDashTargetPosition > X))
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
|
|
|
X = hyperDashTargetPosition;
|
|
|
|
SetHyperDashState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateCatcher()
|
|
|
|
{
|
2020-03-14 16:06:23 +08:00
|
|
|
currentCatcher?.Hide();
|
2020-03-13 11:59:30 +08:00
|
|
|
|
|
|
|
switch (CurrentState)
|
|
|
|
{
|
|
|
|
default:
|
2020-03-14 16:06:23 +08:00
|
|
|
currentCatcher = catcherIdle;
|
2020-03-13 11:59:30 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CatcherAnimationState.Fail:
|
2020-03-14 16:06:23 +08:00
|
|
|
currentCatcher = catcherFail;
|
2020-03-13 11:59:30 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CatcherAnimationState.Kiai:
|
2020-03-14 16:06:23 +08:00
|
|
|
currentCatcher = catcherKiai;
|
2020-03-13 11:59:30 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-03-14 16:06:23 +08:00
|
|
|
currentCatcher.Show();
|
2020-04-03 14:59:56 +08:00
|
|
|
(currentCatcher.Drawable as IFramedAnimation)?.GotoFrame(0);
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState(CatcherAnimationState state)
|
|
|
|
{
|
|
|
|
if (CurrentState == state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CurrentState = state;
|
|
|
|
updateCatcher();
|
|
|
|
}
|
|
|
|
|
2020-12-08 20:29:03 +08:00
|
|
|
private void placeCaughtObject(DrawablePalpableHasCatchHitObject drawableObject, Vector2 position)
|
2020-12-03 13:44:35 +08:00
|
|
|
{
|
2020-12-08 21:38:10 +08:00
|
|
|
var caughtObject = getCaughtObject(drawableObject.HitObject);
|
2020-12-04 13:35:56 +08:00
|
|
|
|
2020-12-03 13:44:35 +08:00
|
|
|
if (caughtObject == null) return;
|
|
|
|
|
2020-12-08 19:34:08 +08:00
|
|
|
caughtObject.CopyFrom(drawableObject);
|
2020-12-08 21:38:10 +08:00
|
|
|
caughtObject.Anchor = Anchor.TopCentre;
|
2020-12-08 19:41:26 +08:00
|
|
|
caughtObject.Position = position;
|
2020-12-08 20:29:03 +08:00
|
|
|
caughtObject.Scale /= 2;
|
2020-12-03 13:44:35 +08:00
|
|
|
|
2020-12-04 13:35:56 +08:00
|
|
|
caughtFruitContainer.Add(caughtObject);
|
|
|
|
|
2020-12-03 13:44:35 +08:00
|
|
|
if (!caughtObject.StaysOnPlate)
|
2020-12-04 13:35:56 +08:00
|
|
|
removeFromPlate(caughtObject, DroppedObjectAnimation.Explode);
|
|
|
|
}
|
|
|
|
|
2020-12-08 11:48:13 +08:00
|
|
|
private Vector2 computePositionInStack(Vector2 position, float displayRadius)
|
2020-12-04 13:35:56 +08:00
|
|
|
{
|
|
|
|
const float radius_div_2 = CatchHitObject.OBJECT_RADIUS / 2;
|
|
|
|
const float allowance = 10;
|
|
|
|
|
2020-12-08 11:48:13 +08:00
|
|
|
while (caughtFruitContainer.Any(f => Vector2Extensions.Distance(f.Position, position) < (displayRadius + radius_div_2) / (allowance / 2)))
|
2020-12-04 13:35:56 +08:00
|
|
|
{
|
2020-12-08 11:48:13 +08:00
|
|
|
float diff = (displayRadius + radius_div_2) / allowance;
|
2020-12-04 13:35:56 +08:00
|
|
|
|
2020-12-08 11:48:13 +08:00
|
|
|
position.X += (RNG.NextSingle() - 0.5f) * diff * 2;
|
|
|
|
position.Y -= RNG.NextSingle() * diff;
|
2020-12-04 13:35:56 +08:00
|
|
|
}
|
|
|
|
|
2020-12-08 11:48:13 +08:00
|
|
|
position.X = Math.Clamp(position.X, -CatcherArea.CATCHER_SIZE / 2, CatcherArea.CATCHER_SIZE / 2);
|
|
|
|
|
|
|
|
return position;
|
2020-12-04 13:35:56 +08:00
|
|
|
}
|
|
|
|
|
2020-12-08 19:41:26 +08:00
|
|
|
private void addLighting(CatchHitObject hitObject, float x, Color4 colour)
|
2020-12-04 13:35:56 +08:00
|
|
|
{
|
|
|
|
HitExplosion hitExplosion = hitExplosionPool.Get();
|
2020-12-08 19:41:26 +08:00
|
|
|
hitExplosion.HitObject = hitObject;
|
|
|
|
hitExplosion.X = x;
|
|
|
|
hitExplosion.Scale = new Vector2(hitObject.Scale);
|
|
|
|
hitExplosion.ObjectColour = colour;
|
2020-12-04 13:35:56 +08:00
|
|
|
hitExplosionContainer.Add(hitExplosion);
|
2020-12-03 13:44:35 +08:00
|
|
|
}
|
|
|
|
|
2020-12-08 21:38:10 +08:00
|
|
|
private CaughtObject getCaughtObject(PalpableCatchHitObject source)
|
2020-12-03 13:44:35 +08:00
|
|
|
{
|
|
|
|
switch (source)
|
|
|
|
{
|
2020-12-08 19:34:08 +08:00
|
|
|
case Fruit _:
|
2020-12-08 21:38:10 +08:00
|
|
|
return caughtFruitPool.Get();
|
2020-12-03 13:44:35 +08:00
|
|
|
|
2020-12-08 19:34:08 +08:00
|
|
|
case Banana _:
|
2020-12-08 21:38:10 +08:00
|
|
|
return caughtBananaPool.Get();
|
2020-12-03 13:44:35 +08:00
|
|
|
|
2020-12-08 19:34:08 +08:00
|
|
|
case Droplet _:
|
2020-12-08 21:38:10 +08:00
|
|
|
return caughtDropletPool.Get();
|
2020-12-03 13:44:35 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-08 21:38:10 +08:00
|
|
|
private CaughtObject getDroppedObject(CaughtObject caughtObject)
|
|
|
|
{
|
|
|
|
var droppedObject = getCaughtObject(caughtObject.HitObject);
|
|
|
|
|
|
|
|
droppedObject.CopyFrom(caughtObject);
|
|
|
|
droppedObject.Anchor = Anchor.TopLeft;
|
|
|
|
droppedObject.Position = caughtFruitContainer.ToSpaceOfOtherDrawable(caughtObject.DrawPosition, droppedObjectTarget);
|
|
|
|
|
|
|
|
return droppedObject;
|
|
|
|
}
|
|
|
|
|
2020-12-02 20:23:34 +08:00
|
|
|
private void clearPlate(DroppedObjectAnimation animation)
|
2020-03-13 11:59:30 +08:00
|
|
|
{
|
2020-12-02 20:23:34 +08:00
|
|
|
var caughtObjects = caughtFruitContainer.Children.ToArray();
|
2020-12-08 21:38:10 +08:00
|
|
|
var droppedObjects = caughtObjects.Select(getDroppedObject).ToArray();
|
|
|
|
|
2020-12-02 20:23:34 +08:00
|
|
|
caughtFruitContainer.Clear(false);
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-08 21:38:10 +08:00
|
|
|
droppedObjectTarget.AddRange(droppedObjects);
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-08 21:38:10 +08:00
|
|
|
foreach (var droppedObject in droppedObjects)
|
|
|
|
applyDropAnimation(droppedObject, animation);
|
2020-12-02 20:23:34 +08:00
|
|
|
}
|
|
|
|
|
2020-12-08 19:34:08 +08:00
|
|
|
private void removeFromPlate(CaughtObject caughtObject, DroppedObjectAnimation animation)
|
2020-12-02 20:23:34 +08:00
|
|
|
{
|
2020-12-08 21:38:10 +08:00
|
|
|
var droppedObject = getDroppedObject(caughtObject);
|
|
|
|
|
2020-12-02 20:23:34 +08:00
|
|
|
if (!caughtFruitContainer.Remove(caughtObject))
|
|
|
|
throw new InvalidOperationException("Can only drop a caught object on the plate");
|
|
|
|
|
2020-12-08 21:38:10 +08:00
|
|
|
droppedObjectTarget.Add(droppedObject);
|
2020-12-02 20:23:34 +08:00
|
|
|
|
2020-12-08 21:38:10 +08:00
|
|
|
applyDropAnimation(droppedObject, animation);
|
2020-12-02 20:23:34 +08:00
|
|
|
}
|
|
|
|
|
2020-12-08 21:38:10 +08:00
|
|
|
private void applyDropAnimation(Drawable d, DroppedObjectAnimation animation)
|
2020-12-02 20:23:34 +08:00
|
|
|
{
|
2020-12-08 19:34:08 +08:00
|
|
|
switch (animation)
|
2020-12-02 20:23:34 +08:00
|
|
|
{
|
2020-12-08 19:34:08 +08:00
|
|
|
case DroppedObjectAnimation.Drop:
|
|
|
|
d.MoveToY(d.Y + 75, 750, Easing.InSine);
|
|
|
|
d.FadeOut(750);
|
|
|
|
break;
|
2020-03-13 11:59:30 +08:00
|
|
|
|
2020-12-08 19:34:08 +08:00
|
|
|
case DroppedObjectAnimation.Explode:
|
2020-12-08 21:38:10 +08:00
|
|
|
var originalX = droppedObjectTarget.ToSpaceOfOtherDrawable(d.DrawPosition, caughtFruitContainer).X * Scale.X;
|
2020-12-08 19:34:08 +08:00
|
|
|
d.MoveToY(d.Y - 50, 250, Easing.OutSine).Then().MoveToY(d.Y + 50, 500, Easing.InSine);
|
|
|
|
d.MoveToX(d.X + originalX * 6, 1000);
|
|
|
|
d.FadeOut(750);
|
|
|
|
break;
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|
2020-12-08 19:34:08 +08:00
|
|
|
|
|
|
|
d.Expire();
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|
2020-12-02 20:23:34 +08:00
|
|
|
|
2020-12-03 17:45:38 +08:00
|
|
|
private enum DroppedObjectAnimation
|
|
|
|
{
|
|
|
|
Drop,
|
|
|
|
Explode
|
|
|
|
}
|
2020-12-02 20:23:34 +08:00
|
|
|
}
|
2020-03-13 11:59:30 +08:00
|
|
|
}
|