1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 12:37:29 +08:00
osu-lazer/osu.Game.Modes.Taiko/Objects/Drawables/DrawableDrumRoll.cs

110 lines
3.9 KiB
C#
Raw Normal View History

2017-03-20 17:24:28 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-04-04 11:38:55 +08:00
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.MathUtils;
using osu.Game.Graphics;
2017-03-20 17:24:28 +08:00
using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.Taiko.Judgements;
2017-04-04 11:38:55 +08:00
using OpenTK;
using OpenTK.Graphics;
using osu.Game.Modes.Taiko.Objects.Drawables.Pieces;
2017-04-04 11:38:55 +08:00
namespace osu.Game.Modes.Taiko.Objects.Drawables
{
public class DrawableDrumRoll : DrawableTaikoHitObject<DrumRoll>
{
/// <summary>
2017-04-01 15:32:31 +08:00
/// Number of rolling hits required to reach the dark/final accent colour.
/// </summary>
2017-04-01 15:32:31 +08:00
private const int rolling_hits_for_dark_accent = 5;
private Color4 accentDarkColour;
/// <summary>
2017-04-01 15:34:30 +08:00
/// Rolling number of tick hits. This increases for hits and decreases for misses.
/// </summary>
2017-04-01 15:32:31 +08:00
private int rollingHits;
public DrawableDrumRoll(DrumRoll drumRoll)
: base(drumRoll)
{
foreach (var tick in drumRoll.Ticks)
{
var newTick = new DrawableDrumRollTick(tick)
{
2017-04-05 12:52:53 +08:00
X = (float)((tick.StartTime - HitObject.StartTime) / HitObject.Duration)
};
newTick.OnJudgement += onTickJudgement;
AddNested(newTick);
MainPiece.Add(newTick);
}
}
protected override TaikoJudgement CreateJudgement() => new TaikoJudgement { SecondHit = HitObject.IsStrong };
protected override TaikoPiece CreateMainPiece() => new ElongatedCirclePiece(HitObject.IsStrong)
{
Length = (float)(HitObject.Duration / HitObject.ScrollTime),
PlayfieldLengthReference = () => Parent.DrawSize.X
};
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
MainPiece.AccentColour = AccentColour = colours.YellowDark;
accentDarkColour = colours.YellowDarker;
}
2017-03-29 08:36:07 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
// This is naive, however it's based on the reasoning that the hit target
// is further than mid point of the play field, so the time taken to scroll in should always
// be greater than the time taken to scroll out to the left of the screen.
// Thus, using PreEmpt here is enough for the drum roll to completely scroll out.
LifetimeEnd = HitObject.EndTime + HitObject.ScrollTime;
2017-03-29 08:36:07 +08:00
}
private void onTickJudgement(DrawableHitObject<TaikoHitObject, TaikoJudgement> obj)
{
if (obj.Judgement.Result == HitResult.Hit)
2017-04-01 15:32:31 +08:00
rollingHits++;
else
2017-04-01 15:32:31 +08:00
rollingHits--;
2017-04-01 15:32:31 +08:00
rollingHits = MathHelper.Clamp(rollingHits, 0, rolling_hits_for_dark_accent);
2017-04-01 15:32:31 +08:00
Color4 newAccent = Interpolation.ValueAt((float)rollingHits / rolling_hits_for_dark_accent, AccentColour, accentDarkColour, 0, 1);
MainPiece.FadeAccent(newAccent, 100);
}
protected override void CheckJudgement(bool userTriggered)
{
if (userTriggered)
return;
if (Judgement.TimeOffset < 0)
return;
int countHit = NestedHitObjects.Count(o => o.Judgement.Result == HitResult.Hit);
if (countHit > HitObject.RequiredGoodHits)
{
Judgement.Result = HitResult.Hit;
Judgement.TaikoResult = countHit >= HitObject.RequiredGreatHits ? TaikoHitResult.Great : TaikoHitResult.Good;
}
else
Judgement.Result = HitResult.Miss;
}
2017-03-28 15:50:06 +08:00
protected override void UpdateState(ArmedState state)
{
}
}
}