mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 17:53:21 +08:00
Add basic implementation of particle explosion
Using drawables still, just to get things in place and setup the structure
This commit is contained in:
parent
3024ae6d86
commit
9df93e1f18
30
osu.Game.Tests/Visual/Gameplay/TestSceneParticleExplosion.cs
Normal file
30
osu.Game.Tests/Visual/Gameplay/TestSceneParticleExplosion.cs
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Game.Graphics;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestSceneParticleExplosion : OsuTestScene
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(TextureStore textures)
|
||||
{
|
||||
AddStep(@"display", () =>
|
||||
{
|
||||
Child = new ParticleExplosion(textures.Get("Cursor/cursortrail"), 150, 1200)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(200)
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
59
osu.Game/Graphics/ParticleExplosion.cs
Normal file
59
osu.Game/Graphics/ParticleExplosion.cs
Normal file
@ -0,0 +1,59 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Utils;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Graphics
|
||||
{
|
||||
public class ParticleExplosion : CompositeDrawable
|
||||
{
|
||||
public ParticleExplosion(Texture texture, int particleCount, double duration)
|
||||
{
|
||||
for (int i = 0; i < particleCount; i++)
|
||||
{
|
||||
double rDuration = RNG.NextDouble(duration / 3, duration);
|
||||
|
||||
AddInternal(new Particle(rDuration, RNG.NextSingle(0, MathF.PI * 2))
|
||||
{
|
||||
Texture = texture
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private class Particle : Sprite
|
||||
{
|
||||
private readonly double duration;
|
||||
private readonly float direction;
|
||||
|
||||
private Vector2 positionForOffset(float offset) => new Vector2(
|
||||
(float)(offset * Math.Sin(direction)),
|
||||
(float)(offset * Math.Cos(direction))
|
||||
);
|
||||
|
||||
public Particle(double duration, float direction)
|
||||
{
|
||||
this.duration = duration;
|
||||
this.direction = direction;
|
||||
Anchor = Anchor.Centre;
|
||||
Origin = Anchor.Centre;
|
||||
RelativePositionAxes = Axes.Both;
|
||||
Position = positionForOffset(0);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
this.MoveTo(positionForOffset(1), duration);
|
||||
this.FadeOut(duration);
|
||||
Expire();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user