1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 19:02:55 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSliderHead.cs

54 lines
1.7 KiB
C#
Raw Normal View History

// 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-04-13 17:19:50 +08:00
using System;
2018-11-09 12:58:46 +08:00
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2018-11-14 13:29:22 +08:00
using osu.Game.Rulesets.Objects;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Objects.Types;
2018-11-20 15:51:59 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public class DrawableSliderHead : DrawableHitCircle
{
2018-11-09 12:58:46 +08:00
private readonly IBindable<Vector2> positionBindable = new Bindable<Vector2>();
2018-11-14 13:29:22 +08:00
private readonly IBindable<SliderPath> pathBindable = new Bindable<SliderPath>();
2018-11-09 12:58:46 +08:00
2018-04-13 17:19:50 +08:00
private readonly Slider slider;
public DrawableSliderHead(Slider slider, HitCircle h)
: base(h)
{
this.slider = slider;
2018-11-09 12:58:46 +08:00
}
2018-04-13 17:19:50 +08:00
2018-11-09 12:58:46 +08:00
[BackgroundDependencyLoader]
private void load()
{
positionBindable.BindTo(HitObject.PositionBindable);
2018-11-14 13:29:22 +08:00
pathBindable.BindTo(slider.PathBindable);
positionBindable.BindValueChanged(_ => updatePosition());
pathBindable.BindValueChanged(_ => updatePosition(), true);
2018-04-13 17:19:50 +08:00
}
protected override void Update()
{
base.Update();
double completionProgress = MathHelper.Clamp((Time.Current - slider.StartTime) / slider.Duration, 0, 1);
//todo: we probably want to reconsider this before adding scoring, but it looks and feels nice.
if (!IsHit)
Position = slider.CurvePositionAt(completionProgress);
}
public Action<double> OnShake;
protected override void Shake(double maximumLength) => OnShake?.Invoke(maximumLength);
private void updatePosition() => Position = HitObject.Position - slider.Position;
2018-04-13 17:19:50 +08:00
}
}