Skip to content

Commit

Permalink
Make hit explosions more interesting
Browse files Browse the repository at this point in the history
  • Loading branch information
swoolcock committed May 31, 2020
1 parent 0af58dd commit e965627
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
64 changes: 61 additions & 3 deletions osu.Game.Rulesets.Rush/UI/DefaultHitExplosion.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Copyright (c) Shane Woolcock. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Utils;
using osuTK;
using osuTK.Graphics;

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

public override bool RemoveWhenNotAlive => true;

public DefaultHitExplosion(Color4 explosionColour)
public DefaultHitExplosion(Color4 explosionColour, int sparkCount = 10, Color4? sparkColour = null)
{
Origin = Anchor.Centre;

InternalChildren = new Drawable[]
{
// TODO: flashbang
colouredExplosion = new Sprite
{
Anchor = Anchor.Centre,
Expand All @@ -38,7 +41,14 @@ public DefaultHitExplosion(Color4 explosionColour)
Origin = Anchor.Centre,
Scale = new Vector2(0.75f)
},
// TODO: small particles
new Sparks(sparkCount)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(2f),
Colour = sparkColour ?? Color4.White
}
// TODO: stars
};
}
Expand All @@ -49,5 +59,53 @@ private void load(TextureStore store)
colouredExplosion.Texture = store.Get("exp");
whiteExplosion.Texture = store.Get("exp");
}

protected class Sparks : CompositeDrawable
{
private const double average_duration = 1500f;

private readonly Random random = new Random();
private readonly Triangle[] triangles;

private double randomDirection(int index, int max)
{
var offset = random.NextDouble() * 2f / max;
return (double)index / max + offset;
}

public Sparks(int sparkCount)
{
Origin = Anchor.Centre;
Anchor = Anchor.Centre;
RelativeSizeAxes = Axes.Both;

triangles = Enumerable.Range(0, sparkCount).Select(i => new Triangle
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Size = new Vector2(5f, 10f),
Rotation = (float)(randomDirection(i, sparkCount) * 360),
}).ToArray();

InternalChildren = triangles;
}

protected override void LoadComplete()
{
base.LoadComplete();

foreach (var triangle in triangles)
{
var scale = 0.8f + random.NextDouble() * 0.2f;
var duration = average_duration * (0.8f + random.NextDouble() * 0.4f);
var radians = MathUtils.DegreesToRadians(triangle.Rotation + 90);
var distance = DrawWidth * (0.8f + random.NextDouble() * 0.2f);
var target = new Vector2(MathF.Cos(radians), MathF.Sin(radians)) * (float)distance;
triangle.Scale = new Vector2((float)scale);
triangle.MoveTo(target, duration, Easing.OutExpo);
triangle.FadeOutFromOne(duration, Easing.InExpo);
}
}
}
}
}
8 changes: 8 additions & 0 deletions osu.Game.Rulesets.Rush/UI/RushPlayfield.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Shane Woolcock. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
Expand All @@ -20,6 +21,8 @@ namespace osu.Game.Rulesets.Rush.UI
[Cached]
public class RushPlayfield : ScrollingPlayfield
{
private readonly Random random = new Random();

public const float DEFAULT_HEIGHT = 178;
public const float HIT_TARGET_OFFSET = 120;
public const float HIT_TARGET_SIZE = 100;
Expand Down Expand Up @@ -191,11 +194,16 @@ private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
case Orb _:
Debug.Assert(drawableLanedHit != null, nameof(drawableLanedHit) + " != null");

// some random rotation and scale for variety
var startScale = 0.9f + random.NextDouble() * 0.2f;
var rotation = random.NextDouble() * 360;
var explosion = new DefaultHitExplosion(drawableLanedHit.LaneAccentColour)
{
Origin = Anchor.Centre,
Anchor = drawableLanedHit.LaneAnchor,
Size = new Vector2(200, 200),
Scale = new Vector2((float)startScale),
Rotation = (float)rotation
};

underEffectContainer.Add(explosion);
Expand Down

0 comments on commit e965627

Please sign in to comment.