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

102 lines
3.1 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.Framework.Graphics.Transforms;
using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.Taiko.Judgements;
using System;
using System.Collections.Generic;
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>
protected abstract List<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:33:23 +08:00
private Container bodyContainer;
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
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
});
}
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)
{
switch (State)
{
case ArmedState.Idle:
break;
case ArmedState.Miss:
bodyContainer.FadeOut(100);
break;
case ArmedState.Hit:
bodyContainer.ScaleTo(0.8f, 400, EasingTypes.OutQuad);
bodyContainer.FadeOut(600, EasingTypes.OutQuint);
bodyContainer.MoveToY(-200, 250, EasingTypes.Out);
bodyContainer.Delay(250);
bodyContainer.MoveToY(0, 500, EasingTypes.In);
break;
}
}
}
}