mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Expand abilities of catcher
This commit is contained in:
parent
c930085213
commit
b71caca131
26
osu.Desktop.Tests/Visual/TestCaseCatcher.cs
Normal file
26
osu.Desktop.Tests/Visual/TestCaseCatcher.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Rulesets.Catch.UI;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Desktop.Tests.Visual
|
||||
{
|
||||
internal class TestCaseCatcher : OsuTestCase
|
||||
{
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new CatcherArea
|
||||
{
|
||||
RelativePositionAxes = Axes.Both,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
Size = new Vector2(1, 0.2f),
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -71,6 +71,7 @@
|
||||
<Compile Include="Visual\TestCaseBeatmapOptionsOverlay.cs" />
|
||||
<Compile Include="Visual\TestCaseBeatSyncedContainer.cs" />
|
||||
<Compile Include="Visual\TestCaseBreadcrumbs.cs" />
|
||||
<Compile Include="Visual\TestCaseCatcher.cs" />
|
||||
<Compile Include="Visual\TestCaseChatDisplay.cs" />
|
||||
<Compile Include="Visual\TestCaseContextMenu.cs" />
|
||||
<Compile Include="Visual\TestCaseDialogOverlay.cs" />
|
||||
|
@ -20,14 +20,12 @@ namespace osu.Game.Rulesets.Catch.UI
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Catcher
|
||||
new CatcherArea
|
||||
{
|
||||
RelativePositionAxes = Axes.Both,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Scale = new Vector2(0.2f),
|
||||
FillMode = FillMode.Fit,
|
||||
Origin = Anchor.TopCentre,
|
||||
Position = new Vector2(0.5f, 1),
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.TopLeft,
|
||||
Height = 0.3f
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,73 +0,0 @@
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Input;
|
||||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace osu.Game.Rulesets.Catch.UI
|
||||
{
|
||||
public class Catcher : Sprite
|
||||
{
|
||||
public override bool HandleInput => true;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(TextureStore textures)
|
||||
{
|
||||
Texture = textures.Get(@"Play/Catch/fruit-catcher-idle");
|
||||
}
|
||||
|
||||
private bool leftPressed;
|
||||
private bool rightPressed;
|
||||
|
||||
private int currentDirection;
|
||||
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
if (args.Repeat) return true;
|
||||
|
||||
switch (args.Key)
|
||||
{
|
||||
case Key.Left:
|
||||
currentDirection = -1;
|
||||
leftPressed = true;
|
||||
return true;
|
||||
case Key.Right:
|
||||
currentDirection = 1;
|
||||
rightPressed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnKeyDown(state, args);
|
||||
}
|
||||
|
||||
protected override bool OnKeyUp(InputState state, KeyUpEventArgs args)
|
||||
{
|
||||
switch (args.Key)
|
||||
{
|
||||
case Key.Left:
|
||||
currentDirection = rightPressed ? 1 : 0;
|
||||
leftPressed = false;
|
||||
|
||||
return true;
|
||||
case Key.Right:
|
||||
currentDirection = leftPressed ? -1 : 0;
|
||||
rightPressed = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnKeyUp(state, args);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (currentDirection == 0) return;
|
||||
|
||||
Scale = new Vector2(Scale.X * (Math.Sign(currentDirection) != Math.Sign(Scale.X) ? -1 : 1), Scale.Y);
|
||||
X = (float)MathHelper.Clamp(X + currentDirection * Clock.ElapsedFrameTime / 1000, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
143
osu.Game.Rulesets.Catch/UI/CatcherArea.cs
Normal file
143
osu.Game.Rulesets.Catch/UI/CatcherArea.cs
Normal file
@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Input;
|
||||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace osu.Game.Rulesets.Catch.UI
|
||||
{
|
||||
public class CatcherArea : Container
|
||||
{
|
||||
public override bool HandleInput => true;
|
||||
|
||||
private Sprite catcher;
|
||||
|
||||
private Drawable createAdditiveFrame() => new Sprite
|
||||
{
|
||||
RelativePositionAxes = Axes.Both,
|
||||
Anchor = Anchor.TopLeft,
|
||||
Origin = Anchor.TopCentre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
FillMode = FillMode.Fit,
|
||||
|
||||
Texture = catcher.Texture,
|
||||
BlendingMode = BlendingMode.Additive,
|
||||
Position = catcher.Position,
|
||||
Scale = catcher.Scale,
|
||||
};
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(TextureStore textures)
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
catcher = new Sprite
|
||||
{
|
||||
RelativePositionAxes = Axes.Both,
|
||||
Anchor = Anchor.TopLeft,
|
||||
Origin = Anchor.TopCentre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
FillMode = FillMode.Fit,
|
||||
|
||||
X = 0.5f,
|
||||
Texture = textures.Get(@"Play/Catch/fruit-catcher-idle"),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private bool leftPressed;
|
||||
private bool rightPressed;
|
||||
|
||||
private int currentDirection;
|
||||
|
||||
private bool dashing;
|
||||
|
||||
protected bool Dashing
|
||||
{
|
||||
get
|
||||
{
|
||||
return dashing;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == dashing) return;
|
||||
|
||||
dashing = value;
|
||||
|
||||
if (dashing)
|
||||
Schedule(addAdditiveSprite);
|
||||
}
|
||||
}
|
||||
|
||||
private void addAdditiveSprite()
|
||||
{
|
||||
if (!dashing) return;
|
||||
|
||||
var additive = createAdditiveFrame();
|
||||
|
||||
Add(additive);
|
||||
|
||||
additive.FadeTo(0.4f).FadeOut(800, Easing.OutQuint).Expire();
|
||||
|
||||
Scheduler.AddDelayed(addAdditiveSprite, 50);
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
if (args.Repeat) return true;
|
||||
|
||||
switch (args.Key)
|
||||
{
|
||||
case Key.Left:
|
||||
currentDirection = -1;
|
||||
leftPressed = true;
|
||||
return true;
|
||||
case Key.Right:
|
||||
currentDirection = 1;
|
||||
rightPressed = true;
|
||||
return true;
|
||||
case Key.ShiftLeft:
|
||||
Dashing = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnKeyDown(state, args);
|
||||
}
|
||||
|
||||
protected override bool OnKeyUp(InputState state, KeyUpEventArgs args)
|
||||
{
|
||||
switch (args.Key)
|
||||
{
|
||||
case Key.Left:
|
||||
currentDirection = rightPressed ? 1 : 0;
|
||||
leftPressed = false;
|
||||
return true;
|
||||
case Key.Right:
|
||||
currentDirection = leftPressed ? -1 : 0;
|
||||
rightPressed = false;
|
||||
return true;
|
||||
case Key.ShiftLeft:
|
||||
Dashing = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnKeyUp(state, args);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (currentDirection == 0) return;
|
||||
|
||||
float speed = Dashing ? 1.5f : 1;
|
||||
|
||||
catcher.Scale = new Vector2(Math.Sign(currentDirection), 1);
|
||||
catcher.X = (float)MathHelper.Clamp(catcher.X + currentDirection * Clock.ElapsedFrameTime / 1800 * speed, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
@ -57,7 +57,7 @@
|
||||
<Compile Include="Objects\Droplet.cs" />
|
||||
<Compile Include="Objects\Fruit.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="UI\Catcher.cs" />
|
||||
<Compile Include="UI\CatcherArea.cs" />
|
||||
<Compile Include="UI\CatchHitRenderer.cs" />
|
||||
<Compile Include="UI\CatchPlayfield.cs" />
|
||||
<Compile Include="CatchRuleset.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user