osu/osu.Game.Modes.Taiko/Objects/Drawables/DrawableHit.cs

114 lines
3.4 KiB
C#
Raw Normal View History

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