Add explosion effect when catching fruit

This commit is contained in:
Dean Herbert 2020-02-21 18:09:50 +09:00
parent e18d736e4a
commit a55b2b8918
3 changed files with 128 additions and 6 deletions

View File

@ -8,7 +8,10 @@
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.Objects.Drawables;
using osu.Game.Rulesets.Catch.UI;
using osu.Game.Tests.Visual;
@ -30,6 +33,10 @@ public TestSceneCatcherArea()
AddToggleStep("Hyperdash", t =>
CreatedDrawables.OfType<CatchInputManager>().Select(i => i.Child)
.OfType<TestCatcherArea>().ForEach(c => c.ToggleHyperDash(t)));
AddRepeatStep("catch fruit", () =>
this.ChildrenOfType<CatcherArea>().ForEach(area =>
area.MovableCatcher.PlaceOnPlate(new DrawableFruit(new TestSceneFruitObjects.TestCatchFruit(FruitVisualRepresentation.Grape)))), 20);
}
private void createCatcher(float size)
@ -58,6 +65,8 @@ public TestCatcherArea(BeatmapDifficulty beatmapDifficulty)
{
}
public new Catcher MovableCatcher => base.MovableCatcher;
public void ToggleHyperDash(bool status) => MovableCatcher.SetHyperDashState(status ? 2 : 1);
}
}

View File

@ -84,11 +84,7 @@ private Drawable createDrawableDroplet()
private Drawable createDrawable(FruitVisualRepresentation rep)
{
Fruit fruit = new TestCatchFruit(rep)
{
StartTime = 1000000000000,
Scale = 1.5f,
};
Fruit fruit = new TestCatchFruit(rep) { Scale = 1.5f };
return new DrawableFruit(fruit)
{
@ -101,11 +97,12 @@ private Drawable createDrawable(FruitVisualRepresentation rep)
};
}
private class TestCatchFruit : Fruit
public class TestCatchFruit : Fruit
{
public TestCatchFruit(FruitVisualRepresentation rep)
{
VisualRepresentation = rep;
StartTime = 1000000000000;
}
public override FruitVisualRepresentation VisualRepresentation { get; }

View File

@ -4,8 +4,10 @@
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Input.Bindings;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
@ -240,6 +242,12 @@ public void PlaceOnPlate(DrawableCatchHitObject fruit)
fruit.X = Math.Clamp(fruit.X, -CATCHER_SIZE / 2, CATCHER_SIZE / 2);
caughtFruit.Add(fruit);
Add(new HitExplosion(fruit)
{
X = fruit.X,
Scale = new Vector2(fruit.HitObject.Scale)
});
}
/// <summary>
@ -465,4 +473,112 @@ void onFruitOnApplyCustomUpdateState(DrawableHitObject o, ArmedState state)
}
}
}
public class HitExplosion : CompositeDrawable
{
private readonly CircularContainer largeFaint;
public HitExplosion(DrawableCatchHitObject fruit)
{
Size = new Vector2(20);
Anchor = Anchor.TopCentre;
Origin = Anchor.BottomCentre;
Color4 objectColour = fruit.AccentColour.Value;
// scale roughly in-line with visual appearance of notes
const float angle_variangle = 15; // should be less than 45
const float roundness = 100;
const float initial_height = 10;
var colour = Interpolation.ValueAt(0.4f, objectColour, Color4.White, 0, 1);
InternalChildren = new Drawable[]
{
largeFaint = new CircularContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
// we want our size to be very small so the glow dominates it.
Size = new Vector2(0.8f),
Blending = BlendingParameters.Additive,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Colour = Interpolation.ValueAt(0.1f, objectColour, Color4.White, 0, 1).Opacity(0.3f),
Roundness = 160,
Radius = 200,
},
},
new CircularContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
Blending = BlendingParameters.Additive,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Colour = Interpolation.ValueAt(0.6f, objectColour, Color4.White, 0, 1),
Roundness = 20,
Radius = 50,
},
},
new CircularContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
Size = new Vector2(0.01f, initial_height),
Blending = BlendingParameters.Additive,
Rotation = RNG.NextSingle(-angle_variangle, angle_variangle),
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Colour = colour,
Roundness = roundness,
Radius = 40,
},
},
new CircularContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
Size = new Vector2(0.01f, initial_height),
Blending = BlendingParameters.Additive,
Rotation = RNG.NextSingle(-angle_variangle, angle_variangle),
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Colour = colour,
Roundness = roundness,
Radius = 40,
},
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
const double duration = 400;
largeFaint
.ResizeTo(largeFaint.Size * new Vector2(5, 1), duration, Easing.OutQuint)
.FadeOut(duration * 2);
this.FadeInFromZero(50).Then().FadeOut(duration, Easing.Out);
Expire(true);
}
}
}