2019-01-24 16:43:03 +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.
|
2018-06-10 08:38:17 +08:00
|
|
|
|
|
2024-09-17 14:27:16 +08:00
|
|
|
|
using System;
|
2020-12-07 13:08:50 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2024-09-17 14:27:16 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2020-12-07 17:57:42 +08:00
|
|
|
|
using osu.Game.Rulesets.Catch.Skinning.Default;
|
2020-12-07 13:08:50 +08:00
|
|
|
|
using osu.Game.Skinning;
|
2024-09-17 14:27:16 +08:00
|
|
|
|
using osuTK;
|
2020-02-19 13:31:32 +08:00
|
|
|
|
|
2020-02-19 17:01:59 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Catch.Objects.Drawables
|
2018-06-10 08:38:17 +08:00
|
|
|
|
{
|
2020-12-09 09:25:35 +08:00
|
|
|
|
public partial class DrawableBanana : DrawablePalpableCatchHitObject
|
2018-06-10 08:38:17 +08:00
|
|
|
|
{
|
2020-11-30 18:07:50 +08:00
|
|
|
|
public DrawableBanana()
|
|
|
|
|
: this(null)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-15 15:27:49 +08:00
|
|
|
|
public DrawableBanana(Banana? h)
|
2018-06-10 08:38:17 +08:00
|
|
|
|
: base(h)
|
|
|
|
|
{
|
|
|
|
|
}
|
2020-02-19 13:31:32 +08:00
|
|
|
|
|
2020-12-07 13:08:50 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2020-12-10 18:42:01 +08:00
|
|
|
|
ScalingContainer.Child = new SkinnableDrawable(
|
2022-11-09 15:04:56 +08:00
|
|
|
|
new CatchSkinComponentLookup(CatchSkinComponents.Banana),
|
2020-12-10 18:42:01 +08:00
|
|
|
|
_ => new BananaPiece());
|
2020-12-07 13:08:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 15:54:18 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2020-12-02 19:53:47 +08:00
|
|
|
|
// start time affects the random seed which is used to determine the banana colour
|
|
|
|
|
StartTimeBindable.BindValueChanged(_ => UpdateComboColour());
|
2020-12-02 15:54:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-17 14:27:16 +08:00
|
|
|
|
private float startScale;
|
|
|
|
|
private float endScale;
|
|
|
|
|
|
|
|
|
|
private float startAngle;
|
|
|
|
|
private float endAngle;
|
|
|
|
|
|
2024-09-17 15:18:29 +08:00
|
|
|
|
protected override void UpdateInitialTransforms()
|
2020-03-10 14:59:13 +08:00
|
|
|
|
{
|
2024-09-17 15:18:29 +08:00
|
|
|
|
base.UpdateInitialTransforms();
|
2020-03-10 14:59:13 +08:00
|
|
|
|
|
2024-09-17 15:18:29 +08:00
|
|
|
|
// Important to have this in UpdateInitialTransforms() to it is re-triggered by RefreshStateTransforms().
|
2020-03-10 14:59:13 +08:00
|
|
|
|
const float end_scale = 0.6f;
|
|
|
|
|
const float random_scale_range = 1.6f;
|
|
|
|
|
|
2024-09-17 14:27:16 +08:00
|
|
|
|
startScale = end_scale + random_scale_range * RandomSingle(3);
|
|
|
|
|
endScale = end_scale;
|
2020-03-10 14:59:13 +08:00
|
|
|
|
|
2024-09-17 14:27:16 +08:00
|
|
|
|
startAngle = getRandomAngle(1);
|
|
|
|
|
endAngle = getRandomAngle(2);
|
2020-03-10 14:59:13 +08:00
|
|
|
|
|
2020-12-02 15:54:18 +08:00
|
|
|
|
float getRandomAngle(int series) => 180 * (RandomSingle(series) * 2 - 1);
|
2020-03-10 14:59:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-17 14:27:16 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2024-09-17 15:15:45 +08:00
|
|
|
|
double preemptProgress = (Time.Current - (HitObject.StartTime - InitialLifetimeOffset)) / HitObject.TimePreempt;
|
|
|
|
|
|
|
|
|
|
// Clamp scale and rotation at the point of bananas being caught, else let them freely extrapolate.
|
|
|
|
|
if (Result.IsHit)
|
|
|
|
|
preemptProgress = Math.Min(1, preemptProgress);
|
|
|
|
|
|
2024-09-17 14:27:16 +08:00
|
|
|
|
ScalingContainer.Scale = new Vector2(HitObject.Scale * (float)Interpolation.Lerp(startScale, endScale, preemptProgress));
|
|
|
|
|
ScalingContainer.Rotation = (float)Interpolation.Lerp(startAngle, endAngle, preemptProgress);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 16:58:49 +08:00
|
|
|
|
public override void PlaySamples()
|
|
|
|
|
{
|
|
|
|
|
base.PlaySamples();
|
|
|
|
|
if (Samples != null)
|
|
|
|
|
Samples.Frequency.Value = 0.77f + ((Banana)HitObject).BananaIndex * 0.006f;
|
|
|
|
|
}
|
2018-06-10 08:38:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|