osu/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs

79 lines
2.5 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
2017-04-18 07:05:58 +00:00
using osu.Game.Rulesets.UI;
using OpenTK;
2017-08-08 01:35:56 +00:00
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Catch.Objects;
2017-08-08 03:46:37 +00:00
using osu.Game.Rulesets.Catch.Objects.Drawable;
using osu.Game.Rulesets.Judgements;
2017-08-08 03:46:37 +00:00
using osu.Game.Rulesets.Objects.Drawables;
2017-04-18 07:05:58 +00:00
namespace osu.Game.Rulesets.Catch.UI
{
public class CatchPlayfield : ScrollingPlayfield
{
public const float BASE_WIDTH = 512;
2017-10-10 07:34:01 +00:00
2017-08-08 01:35:56 +00:00
protected override Container<Drawable> Content => content;
private readonly Container<Drawable> content;
private readonly CatcherArea catcherArea;
2017-08-08 01:35:56 +00:00
public CatchPlayfield(BeatmapDifficulty difficulty)
: base(Direction.Vertical)
{
Container explodingFruitContainer;
2017-08-02 11:41:38 +00:00
Anchor = Anchor.TopCentre;
Origin = Anchor.TopCentre;
2017-08-08 01:35:56 +00:00
InternalChildren = new Drawable[]
2017-08-02 11:28:24 +00:00
{
2017-08-08 01:35:56 +00:00
content = new Container<Drawable>
{
RelativeSizeAxes = Axes.Both,
},
explodingFruitContainer = new Container
2017-08-02 11:28:24 +00:00
{
RelativeSizeAxes = Axes.Both,
},
catcherArea = new CatcherArea(difficulty)
2017-10-02 14:24:22 +00:00
{
ExplodingFruitTarget = explodingFruitContainer,
2017-08-07 06:09:31 +00:00
Anchor = Anchor.BottomLeft,
Origin = Anchor.TopLeft,
2017-08-02 11:28:24 +00:00
}
};
}
2017-08-08 03:46:37 +00:00
public bool CheckIfWeCanCatch(CatchHitObject obj) => catcherArea.AttemptCatch(obj);
public override void Add(DrawableHitObject h)
2017-08-08 03:46:37 +00:00
{
h.Depth = (float)h.HitObject.StartTime;
2017-08-08 03:46:37 +00:00
base.Add(h);
2017-10-10 07:34:01 +00:00
var fruit = (DrawableCatchHitObject)h;
fruit.CheckPosition = CheckIfWeCanCatch;
2017-08-08 03:46:37 +00:00
}
2017-09-13 07:15:11 +00:00
public override void OnJudgement(DrawableHitObject judgedObject, Judgement judgement)
2017-08-08 03:46:37 +00:00
{
2017-09-12 08:36:46 +00:00
if (judgement.IsHit)
2017-08-08 03:46:37 +00:00
{
Vector2 screenPosition = judgedObject.ScreenSpaceDrawQuad.Centre;
// todo: don't do this
(judgedObject.Parent as Container<DrawableHitObject>)?.Remove(judgedObject);
(judgedObject.Parent as Container)?.Remove(judgedObject);
catcherArea.Add(judgedObject, screenPosition);
2017-08-08 03:46:37 +00:00
}
}
}
2017-08-08 01:35:56 +00:00
}