1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-07 13:07:25 +08:00
osu-lazer/osu.Game.Modes.Taiko/Objects/Drawable/DrawableHit.cs

105 lines
3.2 KiB
C#
Raw Normal View History

2017-03-20 17:25:12 +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
using OpenTK.Input;
2017-03-28 09:33:23 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.Taiko.Judgements;
using System;
2017-03-29 14:35:22 +08:00
using System.Linq;
namespace osu.Game.Modes.Taiko.Objects.Drawable
{
2017-03-17 18:24:39 +08:00
public abstract class DrawableHit : DrawableTaikoHitObject
{
/// <summary>
/// A list of keys which can result in hits for this HitObject.
/// </summary>
2017-03-29 14:35:22 +08:00
protected abstract Key[] HitKeys { get; }
2017-03-28 09:33:23 +08:00
protected override Container<Framework.Graphics.Drawable> Content => bodyContainer;
2017-03-24 13:59:59 +08:00
private readonly Hit hit;
/// <summary>
/// Whether the last key pressed is a valid hit key.
/// </summary>
private bool validKeyPressed;
2017-03-28 09:51:22 +08:00
private readonly Container bodyContainer;
2017-03-28 09:33:23 +08:00
2017-03-24 13:59:59 +08:00
protected DrawableHit(Hit hit)
: base(hit)
{
2017-03-24 13:59:59 +08:00
this.hit = hit;
2017-03-28 09:33:23 +08:00
AddInternal(bodyContainer = new Container
{
2017-03-29 12:07:36 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2017-03-28 09:33:23 +08:00
});
}
protected override void CheckJudgement(bool userTriggered)
{
if (!userTriggered)
{
2017-03-24 13:59:59 +08:00
if (Judgement.TimeOffset > hit.HitWindowGood)
Judgement.Result = HitResult.Miss;
return;
}
double hitOffset = Math.Abs(Judgement.TimeOffset);
2017-03-24 13:59:59 +08:00
if (hitOffset > hit.HitWindowMiss)
return;
if (!validKeyPressed)
Judgement.Result = HitResult.Miss;
2017-03-24 13:59:59 +08:00
else if (hitOffset < hit.HitWindowGood)
{
Judgement.Result = HitResult.Hit;
2017-03-24 13:59:59 +08:00
Judgement.TaikoResult = hitOffset < hit.HitWindowGreat ? TaikoHitResult.Great : TaikoHitResult.Good;
}
else
Judgement.Result = HitResult.Miss;
}
protected override bool HandleKeyPress(Key key)
{
if (Judgement.Result.HasValue)
return false;
validKeyPressed = HitKeys.Contains(key);
return UpdateJudgement(true);
}
2017-03-28 09:33:23 +08:00
protected override void UpdateState(ArmedState state)
{
Delay(HitObject.StartTime - Time.Current + Judgement.TimeOffset, true);
2017-03-28 09:33:23 +08:00
switch (State)
{
case ArmedState.Idle:
Delay(hit.HitWindowMiss);
2017-03-28 09:33:23 +08:00
break;
case ArmedState.Miss:
2017-03-29 08:11:07 +08:00
FadeOut(100);
2017-03-28 09:33:23 +08:00
break;
case ArmedState.Hit:
bodyContainer.ScaleTo(0.8f, 400, EasingTypes.OutQuad);
bodyContainer.MoveToY(-200, 250, EasingTypes.Out);
bodyContainer.Delay(250);
bodyContainer.MoveToY(0, 500, EasingTypes.In);
2017-03-29 08:11:07 +08:00
FadeOut(600);
2017-03-28 09:33:23 +08:00
break;
}
Expire();
2017-03-28 09:33:23 +08:00
}
}
}