mirror of
https://github.com/ppy/osu.git
synced 2024-11-07 10:17:43 +08:00
Add basic DrawableHit (no graphics yet, just input).
This commit is contained in:
parent
35f63cb2aa
commit
f26cf7bf68
82
osu.Game.Modes.Taiko/Objects/Drawable/DrawableHit.cs
Normal file
82
osu.Game.Modes.Taiko/Objects/Drawable/DrawableHit.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using OpenTK.Input;
|
||||
using osu.Framework.Input;
|
||||
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
|
||||
{
|
||||
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; }
|
||||
|
||||
/// <summary>
|
||||
/// A list of keys which this hit object will accept. These are the standard Taiko keys for now.
|
||||
/// These should be moved to bindings later.
|
||||
/// </summary>
|
||||
private List<Key> validKeys = new List<Key>(new[] { Key.D, Key.F, Key.J, Key.K });
|
||||
|
||||
/// <summary>
|
||||
/// Whether the last key pressed is a valid hit key.
|
||||
/// </summary>
|
||||
private bool validKeyPressed;
|
||||
|
||||
protected DrawableHit(TaikoHitObject hitObject)
|
||||
: base(hitObject)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void CheckJudgement(bool userTriggered)
|
||||
{
|
||||
if (!userTriggered)
|
||||
{
|
||||
if (Judgement.TimeOffset > HitObject.HitWindowGood)
|
||||
Judgement.Result = HitResult.Miss;
|
||||
return;
|
||||
}
|
||||
|
||||
double hitOffset = Math.Abs(Judgement.TimeOffset);
|
||||
|
||||
if (hitOffset > HitObject.HitWindowMiss)
|
||||
return;
|
||||
|
||||
if (!validKeyPressed)
|
||||
Judgement.Result = HitResult.Miss;
|
||||
else if (hitOffset < HitObject.HitWindowGood)
|
||||
{
|
||||
Judgement.Result = HitResult.Hit;
|
||||
Judgement.Score = hitOffset < HitObject.HitWindowGreat ? TaikoScoreResult.Great : TaikoScoreResult.Good;
|
||||
}
|
||||
else
|
||||
Judgement.Result = HitResult.Miss;
|
||||
}
|
||||
|
||||
protected virtual bool HandleKeyPress(Key key)
|
||||
{
|
||||
if (Judgement.Result.HasValue)
|
||||
return false;
|
||||
|
||||
validKeyPressed = HitKeys.Contains(key);
|
||||
|
||||
return UpdateJudgement(true);
|
||||
}
|
||||
|
||||
protected sealed override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
// Make sure we don't handle held-down keys
|
||||
if (args.Repeat)
|
||||
return false;
|
||||
|
||||
// Check if we've pressed a valid taiko key
|
||||
if (!validKeys.Contains(args.Key))
|
||||
return false;
|
||||
|
||||
// Handle it!
|
||||
return HandleKeyPress(args.Key);
|
||||
}
|
||||
}
|
||||
}
|
@ -50,6 +50,7 @@
|
||||
<Compile Include="Beatmaps\TaikoBeatmapConverter.cs" />
|
||||
<Compile Include="Beatmaps\TaikoBeatmapProcessor.cs" />
|
||||
<Compile Include="Judgements\TaikoJudgementInfo.cs" />
|
||||
<Compile Include="Objects\Drawable\DrawableHit.cs" />
|
||||
<Compile Include="Objects\Drawable\DrawableTaikoHitObject.cs" />
|
||||
<Compile Include="Objects\TaikoHitType.cs" />
|
||||
<Compile Include="TaikoDifficultyCalculator.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user