mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 18:42:56 +08:00
Add basic Catcher
This commit is contained in:
parent
554d0d6fb8
commit
81b738f68c
@ -18,7 +18,23 @@ namespace osu.Game.Rulesets.Catch.UI
|
|||||||
Anchor = Anchor.BottomCentre;
|
Anchor = Anchor.BottomCentre;
|
||||||
Origin = Anchor.BottomCentre;
|
Origin = Anchor.BottomCentre;
|
||||||
|
|
||||||
Add(new Box { RelativeSizeAxes = Axes.Both, Alpha = 0.5f });
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Alpha = 0.5f
|
||||||
|
},
|
||||||
|
new Catcher
|
||||||
|
{
|
||||||
|
RelativePositionAxes = Axes.Both,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Scale = new Vector2(0.2f),
|
||||||
|
FillMode = FillMode.Fit,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Position = new Vector2(0.5f, 0.9f),
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
73
osu.Game.Rulesets.Catch/UI/Catcher.cs
Normal file
73
osu.Game.Rulesets.Catch/UI/Catcher.cs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -57,6 +57,7 @@
|
|||||||
<Compile Include="Objects\Droplet.cs" />
|
<Compile Include="Objects\Droplet.cs" />
|
||||||
<Compile Include="Objects\Fruit.cs" />
|
<Compile Include="Objects\Fruit.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="UI\Catcher.cs" />
|
||||||
<Compile Include="UI\CatchHitRenderer.cs" />
|
<Compile Include="UI\CatchHitRenderer.cs" />
|
||||||
<Compile Include="UI\CatchPlayfield.cs" />
|
<Compile Include="UI\CatchPlayfield.cs" />
|
||||||
<Compile Include="CatchRuleset.cs" />
|
<Compile Include="CatchRuleset.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user