diff --git a/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs b/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs index 8be52150fc..3aa5b3f1e3 100644 --- a/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs +++ b/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs @@ -18,7 +18,23 @@ namespace osu.Game.Rulesets.Catch.UI Anchor = 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), + } + }; } } } \ No newline at end of file diff --git a/osu.Game.Rulesets.Catch/UI/Catcher.cs b/osu.Game.Rulesets.Catch/UI/Catcher.cs new file mode 100644 index 0000000000..42e4f03da1 --- /dev/null +++ b/osu.Game.Rulesets.Catch/UI/Catcher.cs @@ -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); + } + } +} diff --git a/osu.Game.Rulesets.Catch/osu.Game.Rulesets.Catch.csproj b/osu.Game.Rulesets.Catch/osu.Game.Rulesets.Catch.csproj index 83996df41a..f84f9302bb 100644 --- a/osu.Game.Rulesets.Catch/osu.Game.Rulesets.Catch.csproj +++ b/osu.Game.Rulesets.Catch/osu.Game.Rulesets.Catch.csproj @@ -57,6 +57,7 @@ +