1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 03:02:53 +08:00
osu-lazer/osu.Game.Rulesets.Catch/Objects/Drawable/DrawableFruit.cs

127 lines
4.2 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
2017-08-08 11:46:37 +08:00
using System;
2016-11-14 17:03:20 +08:00
using osu.Framework.Allocation;
2017-08-03 07:32:38 +08:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
2017-08-03 07:32:38 +08:00
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.MathUtils;
2017-08-03 07:32:38 +08:00
using osu.Game.Graphics;
using osu.Game.Rulesets.Catch.Judgements;
using osu.Game.Rulesets.Objects.Drawables;
using OpenTK;
2017-08-03 07:32:38 +08:00
using OpenTK.Graphics;
2017-04-18 15:05:58 +08:00
namespace osu.Game.Rulesets.Catch.Objects.Drawable
{
2017-08-08 11:46:37 +08:00
public class DrawableFruit : DrawableScrollingHitObject<CatchBaseHit, CatchJudgement>
{
2017-08-09 09:16:31 +08:00
private const float pulp_size = 30;
2017-08-08 09:36:05 +08:00
2017-08-03 07:32:38 +08:00
private class Pulp : Circle, IHasAccentColour
{
public Pulp()
{
Size = new Vector2(pulp_size);
2017-08-03 07:32:38 +08:00
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Radius = 5,
Colour = AccentColour.Opacity(0.5f),
};
}
public Color4 AccentColour { get; set; } = Color4.White;
}
2017-08-08 11:46:37 +08:00
public DrawableFruit(CatchBaseHit h)
: base(h)
{
Origin = Anchor.Centre;
Size = new Vector2(pulp_size * 2, pulp_size * 2.6f);
2017-08-08 09:35:56 +08:00
RelativePositionAxes = Axes.Both;
2017-08-08 09:35:56 +08:00
X = h.Position;
Colour = new Color4(RNG.NextSingle(), RNG.NextSingle(), RNG.NextSingle(), 1);
2017-08-08 09:35:56 +08:00
Rotation = (float)(RNG.NextDouble() - 0.5f) * 40;
}
2017-08-08 11:46:37 +08:00
public Func<CatchBaseHit, bool> CheckPosition;
[BackgroundDependencyLoader]
private void load()
{
Children = new Framework.Graphics.Drawable[]
{
//todo: share this more
new BufferedContainer
{
RelativeSizeAxes = Axes.Both,
CacheDrawnFrameBuffer = true,
Children = new Framework.Graphics.Drawable[]
{
new Pulp
{
RelativePositionAxes = Axes.Both,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Scale = new Vector2(0.6f),
},
new Pulp
{
RelativePositionAxes = Axes.Both,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Y = -0.08f
},
new Pulp
{
RelativePositionAxes = Axes.Both,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Y = -0.08f
},
new Pulp
{
RelativePositionAxes = Axes.Both,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
},
}
}
};
}
private const float preempt = 1000;
2017-08-08 09:36:05 +08:00
protected override void CheckJudgement(bool userTriggered)
{
if (Judgement.TimeOffset > 0)
2017-09-05 18:44:59 +08:00
Judgement.Result = CheckPosition?.Invoke(HitObject) ?? false ? HitResult.Perfect : HitResult.Miss;
2017-08-08 09:36:05 +08:00
}
protected override void UpdateState(ArmedState state)
{
using (BeginAbsoluteSequence(HitObject.StartTime - preempt))
{
// animation
2017-08-08 09:35:56 +08:00
this.FadeIn(200);
}
2017-08-08 09:36:05 +08:00
switch (state)
{
case ArmedState.Miss:
using (BeginAbsoluteSequence(HitObject.StartTime, true))
this.FadeOut(250).RotateTo(Rotation * 2, 250, Easing.Out);
break;
}
}
}
}