2017-08-08 06:32:23 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
2017-08-08 11:46:37 +08:00
|
|
|
|
using System.Linq;
|
2017-08-07 14:09:31 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2017-08-11 15:11:46 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2017-08-08 11:46:37 +08:00
|
|
|
|
using osu.Framework.MathUtils;
|
|
|
|
|
using osu.Game.Rulesets.Catch.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Catch.Objects.Drawable;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2017-08-07 14:09:31 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.UI
|
|
|
|
|
{
|
|
|
|
|
public class CatcherArea : Container
|
|
|
|
|
{
|
2017-08-08 11:46:37 +08:00
|
|
|
|
private Catcher catcher;
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-09-06 16:02:13 +08:00
|
|
|
|
public void Add(DrawableHitObject fruit, Vector2 screenPosition) => catcher.AddToStack(fruit, screenPosition);
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
public bool CheckIfWeCanCatch(CatchBaseHit obj) => Math.Abs(catcher.Position.X - obj.Position) < catcher.DrawSize.X / DrawSize.X / 2;
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2017-08-08 11:46:37 +08:00
|
|
|
|
private void load()
|
2017-08-07 14:09:31 +08:00
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-08-08 11:46:37 +08:00
|
|
|
|
catcher = new Catcher
|
2017-08-07 14:09:31 +08:00
|
|
|
|
{
|
|
|
|
|
RelativePositionAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
X = 0.5f,
|
2017-08-08 11:46:37 +08:00
|
|
|
|
}
|
2017-08-07 14:09:31 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
catcher.Size = new Vector2(DrawSize.Y);
|
|
|
|
|
}
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-08-12 18:54:07 +08:00
|
|
|
|
private class Catcher : Container, IKeyBindingHandler<CatchAction>
|
2017-08-07 14:09:31 +08:00
|
|
|
|
{
|
2017-08-08 11:46:37 +08:00
|
|
|
|
private Texture texture;
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(TextureStore textures)
|
2017-08-07 14:09:31 +08:00
|
|
|
|
{
|
2017-08-08 11:46:37 +08:00
|
|
|
|
texture = textures.Get(@"Play/Catch/fruit-catcher-idle");
|
|
|
|
|
|
|
|
|
|
Child = createCatcherSprite();
|
2017-08-07 14:09:31 +08:00
|
|
|
|
}
|
2017-08-08 11:46:37 +08:00
|
|
|
|
|
|
|
|
|
private int currentDirection;
|
|
|
|
|
|
|
|
|
|
private bool dashing;
|
|
|
|
|
|
|
|
|
|
protected bool Dashing
|
2017-08-07 14:09:31 +08:00
|
|
|
|
{
|
2017-08-08 11:46:37 +08:00
|
|
|
|
get { return dashing; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == dashing) return;
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
dashing = value;
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
if (dashing)
|
|
|
|
|
Schedule(addAdditiveSprite);
|
|
|
|
|
}
|
2017-08-07 14:09:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
private void addAdditiveSprite()
|
|
|
|
|
{
|
|
|
|
|
if (!dashing) return;
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
var additive = createCatcherSprite();
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
additive.RelativePositionAxes = Axes.Both;
|
2017-09-07 21:46:21 +08:00
|
|
|
|
additive.Blending = BlendingMode.Additive;
|
2017-08-08 11:46:37 +08:00
|
|
|
|
additive.Position = Position;
|
|
|
|
|
additive.Scale = Scale;
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
((CatcherArea)Parent).Add(additive);
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
additive.FadeTo(0.4f).FadeOut(800, Easing.OutQuint).Expire();
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
Scheduler.AddDelayed(addAdditiveSprite, 50);
|
|
|
|
|
}
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
private Sprite createCatcherSprite() => new Sprite
|
2017-08-07 14:09:31 +08:00
|
|
|
|
{
|
2017-08-08 11:46:37 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
FillMode = FillMode.Fit,
|
|
|
|
|
Texture = texture,
|
|
|
|
|
OriginPosition = new Vector2(DrawWidth / 2, 10) //temporary until the sprite is aligned correctly.
|
|
|
|
|
};
|
|
|
|
|
|
2017-08-10 18:28:24 +08:00
|
|
|
|
public bool OnPressed(CatchAction action)
|
2017-08-08 11:46:37 +08:00
|
|
|
|
{
|
2017-08-10 18:28:24 +08:00
|
|
|
|
switch (action)
|
2017-08-08 11:46:37 +08:00
|
|
|
|
{
|
2017-08-10 18:28:24 +08:00
|
|
|
|
case CatchAction.MoveLeft:
|
|
|
|
|
currentDirection--;
|
|
|
|
|
return true;
|
|
|
|
|
case CatchAction.MoveRight:
|
|
|
|
|
currentDirection++;
|
|
|
|
|
return true;
|
|
|
|
|
case CatchAction.Dash:
|
|
|
|
|
Dashing = true;
|
|
|
|
|
return true;
|
2017-08-08 11:46:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 18:28:24 +08:00
|
|
|
|
return false;
|
2017-08-07 14:09:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 18:28:24 +08:00
|
|
|
|
public bool OnReleased(CatchAction action)
|
2017-08-08 11:46:37 +08:00
|
|
|
|
{
|
2017-08-10 18:28:24 +08:00
|
|
|
|
switch (action)
|
2017-08-08 11:46:37 +08:00
|
|
|
|
{
|
2017-08-10 18:28:24 +08:00
|
|
|
|
case CatchAction.MoveLeft:
|
|
|
|
|
currentDirection++;
|
|
|
|
|
return true;
|
|
|
|
|
case CatchAction.MoveRight:
|
|
|
|
|
currentDirection--;
|
|
|
|
|
return true;
|
|
|
|
|
case CatchAction.Dash:
|
|
|
|
|
Dashing = false;
|
|
|
|
|
return true;
|
2017-08-08 11:46:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 18:28:24 +08:00
|
|
|
|
return false;
|
2017-08-08 11:46:37 +08:00
|
|
|
|
}
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-09-15 18:32:46 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The relative space to cover in 1 millisecond. based on 1 game pixel per millisecond as in osu-stable.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const double base_speed = 1.0 / 512;
|
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
protected override void Update()
|
2017-08-07 14:09:31 +08:00
|
|
|
|
{
|
2017-08-08 11:46:37 +08:00
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
if (currentDirection == 0) return;
|
|
|
|
|
|
2017-09-15 18:32:46 +08:00
|
|
|
|
double dashModifier = Dashing ? 1 : 0.5;
|
2017-08-08 11:46:37 +08:00
|
|
|
|
|
|
|
|
|
Scale = new Vector2(Math.Sign(currentDirection), 1);
|
2017-09-15 18:32:46 +08:00
|
|
|
|
X = (float)MathHelper.Clamp(X + Math.Sign(currentDirection) * Clock.ElapsedFrameTime * base_speed * dashModifier, 0, 1);
|
2017-08-07 14:09:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-06 16:02:13 +08:00
|
|
|
|
public void AddToStack(DrawableHitObject fruit, Vector2 absolutePosition)
|
2017-08-08 11:46:37 +08:00
|
|
|
|
{
|
|
|
|
|
fruit.RelativePositionAxes = Axes.None;
|
|
|
|
|
fruit.Position = new Vector2(ToLocalSpace(absolutePosition).X - DrawSize.X / 2, 0);
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
fruit.Anchor = Anchor.TopCentre;
|
|
|
|
|
fruit.Origin = Anchor.BottomCentre;
|
|
|
|
|
fruit.Scale *= 0.7f;
|
|
|
|
|
fruit.LifetimeEnd = double.MaxValue;
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
float distance = fruit.DrawSize.X / 2 * fruit.Scale.X;
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-09-13 19:25:40 +08:00
|
|
|
|
while (Children.OfType<DrawableFruit>().Any(f => Vector2Extensions.DistanceSquared(f.Position, fruit.Position) < distance * distance))
|
2017-08-08 11:46:37 +08:00
|
|
|
|
{
|
|
|
|
|
fruit.X += RNG.Next(-5, 5);
|
|
|
|
|
fruit.Y -= RNG.Next(0, 5);
|
|
|
|
|
}
|
2017-08-07 14:09:31 +08:00
|
|
|
|
|
2017-08-08 11:46:37 +08:00
|
|
|
|
Add(fruit);
|
|
|
|
|
}
|
2017-08-07 14:09:31 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|