Add basic Catcher

This commit is contained in:
Dean Herbert 2017-08-02 20:28:24 +09:00
parent 554d0d6fb8
commit 81b738f68c
3 changed files with 91 additions and 1 deletions

View File

@ -18,7 +18,23 @@ public CatchPlayfield()
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),
}
};
}
}
}

View 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);
}
}
}

View File

@ -57,6 +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\CatchHitRenderer.cs" />
<Compile Include="UI\CatchPlayfield.cs" />
<Compile Include="CatchRuleset.cs" />