Skip to content

Commit e965627

Browse files
committed
Make hit explosions more interesting
1 parent 0af58dd commit e965627

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

osu.Game.Rulesets.Rush/UI/DefaultHitExplosion.cs

+61-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// Copyright (c) Shane Woolcock. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4+
using System;
5+
using System.Linq;
46
using osu.Framework.Allocation;
57
using osu.Framework.Graphics;
68
using osu.Framework.Graphics.Containers;
9+
using osu.Framework.Graphics.Shapes;
710
using osu.Framework.Graphics.Sprites;
811
using osu.Framework.Graphics.Textures;
12+
using osu.Framework.Utils;
913
using osuTK;
1014
using osuTK.Graphics;
1115

@@ -18,13 +22,12 @@ public class DefaultHitExplosion : CompositeDrawable
1822

1923
public override bool RemoveWhenNotAlive => true;
2024

21-
public DefaultHitExplosion(Color4 explosionColour)
25+
public DefaultHitExplosion(Color4 explosionColour, int sparkCount = 10, Color4? sparkColour = null)
2226
{
2327
Origin = Anchor.Centre;
2428

2529
InternalChildren = new Drawable[]
2630
{
27-
// TODO: flashbang
2831
colouredExplosion = new Sprite
2932
{
3033
Anchor = Anchor.Centre,
@@ -38,7 +41,14 @@ public DefaultHitExplosion(Color4 explosionColour)
3841
Origin = Anchor.Centre,
3942
Scale = new Vector2(0.75f)
4043
},
41-
// TODO: small particles
44+
new Sparks(sparkCount)
45+
{
46+
Anchor = Anchor.Centre,
47+
Origin = Anchor.Centre,
48+
RelativeSizeAxes = Axes.Both,
49+
Size = new Vector2(2f),
50+
Colour = sparkColour ?? Color4.White
51+
}
4252
// TODO: stars
4353
};
4454
}
@@ -49,5 +59,53 @@ private void load(TextureStore store)
4959
colouredExplosion.Texture = store.Get("exp");
5060
whiteExplosion.Texture = store.Get("exp");
5161
}
62+
63+
protected class Sparks : CompositeDrawable
64+
{
65+
private const double average_duration = 1500f;
66+
67+
private readonly Random random = new Random();
68+
private readonly Triangle[] triangles;
69+
70+
private double randomDirection(int index, int max)
71+
{
72+
var offset = random.NextDouble() * 2f / max;
73+
return (double)index / max + offset;
74+
}
75+
76+
public Sparks(int sparkCount)
77+
{
78+
Origin = Anchor.Centre;
79+
Anchor = Anchor.Centre;
80+
RelativeSizeAxes = Axes.Both;
81+
82+
triangles = Enumerable.Range(0, sparkCount).Select(i => new Triangle
83+
{
84+
Origin = Anchor.Centre,
85+
Anchor = Anchor.Centre,
86+
Size = new Vector2(5f, 10f),
87+
Rotation = (float)(randomDirection(i, sparkCount) * 360),
88+
}).ToArray();
89+
90+
InternalChildren = triangles;
91+
}
92+
93+
protected override void LoadComplete()
94+
{
95+
base.LoadComplete();
96+
97+
foreach (var triangle in triangles)
98+
{
99+
var scale = 0.8f + random.NextDouble() * 0.2f;
100+
var duration = average_duration * (0.8f + random.NextDouble() * 0.4f);
101+
var radians = MathUtils.DegreesToRadians(triangle.Rotation + 90);
102+
var distance = DrawWidth * (0.8f + random.NextDouble() * 0.2f);
103+
var target = new Vector2(MathF.Cos(radians), MathF.Sin(radians)) * (float)distance;
104+
triangle.Scale = new Vector2((float)scale);
105+
triangle.MoveTo(target, duration, Easing.OutExpo);
106+
triangle.FadeOutFromOne(duration, Easing.InExpo);
107+
}
108+
}
109+
}
52110
}
53111
}

osu.Game.Rulesets.Rush/UI/RushPlayfield.cs

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Shane Woolcock. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4+
using System;
45
using System.Diagnostics;
56
using osu.Framework.Allocation;
67
using osu.Framework.Extensions.Color4Extensions;
@@ -20,6 +21,8 @@ namespace osu.Game.Rulesets.Rush.UI
2021
[Cached]
2122
public class RushPlayfield : ScrollingPlayfield
2223
{
24+
private readonly Random random = new Random();
25+
2326
public const float DEFAULT_HEIGHT = 178;
2427
public const float HIT_TARGET_OFFSET = 120;
2528
public const float HIT_TARGET_SIZE = 100;
@@ -191,11 +194,16 @@ private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
191194
case Orb _:
192195
Debug.Assert(drawableLanedHit != null, nameof(drawableLanedHit) + " != null");
193196

197+
// some random rotation and scale for variety
198+
var startScale = 0.9f + random.NextDouble() * 0.2f;
199+
var rotation = random.NextDouble() * 360;
194200
var explosion = new DefaultHitExplosion(drawableLanedHit.LaneAccentColour)
195201
{
196202
Origin = Anchor.Centre,
197203
Anchor = drawableLanedHit.LaneAnchor,
198204
Size = new Vector2(200, 200),
205+
Scale = new Vector2((float)startScale),
206+
Rotation = (float)rotation
199207
};
200208

201209
underEffectContainer.Add(explosion);

0 commit comments

Comments
 (0)