1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 03:47:26 +08:00
osu-lazer/osu.Game/Screens/Menu/StarFountain.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

99 lines
3.3 KiB
C#
Raw Normal View History

2023-07-13 19:31:00 +08:00
// 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 osu.Framework.Allocation;
using osu.Framework.Graphics.Textures;
using osu.Framework.Threading;
2023-07-13 19:31:00 +08:00
using osu.Framework.Utils;
using osu.Game.Graphics;
2023-07-13 21:30:27 +08:00
using osu.Game.Skinning;
2023-07-13 19:31:00 +08:00
using osuTK;
namespace osu.Game.Screens.Menu
{
public partial class StarFountain : SkinReloadableDrawable
2023-07-13 19:31:00 +08:00
{
private StarFountainSpewer spewer = null!;
[Resolved]
private TextureStore textures { get; set; } = null!;
2023-07-13 19:31:00 +08:00
[BackgroundDependencyLoader]
private void load()
{
InternalChild = spewer = new StarFountainSpewer();
2023-07-13 19:31:00 +08:00
}
public void Shoot(int direction) => spewer.Shoot(direction);
protected override void SkinChanged(ISkinSource skin)
2023-07-13 19:31:00 +08:00
{
base.SkinChanged(skin);
spewer.Texture = skin.GetTexture("Menu/fountain-star") ?? textures.Get("Menu/fountain-star");
}
2023-07-13 19:31:00 +08:00
public partial class StarFountainSpewer : ParticleSpewer
{
private const int particle_duration_min = 300;
private const int particle_duration_max = 1000;
2023-07-13 22:12:29 +08:00
private double? lastShootTime;
private int lastShootDirection;
2023-07-13 22:12:29 +08:00
protected override float ParticleGravity => 800;
2023-07-13 22:12:29 +08:00
private const double shoot_duration = 800;
2023-07-13 19:31:00 +08:00
[Resolved]
private ISkinSource skin { get; set; } = null!;
2023-07-13 22:12:29 +08:00
public StarFountainSpewer()
: base(null, 240, particle_duration_max)
{
2023-07-13 19:31:00 +08:00
}
[BackgroundDependencyLoader]
private void load(TextureStore textures)
2023-07-13 19:31:00 +08:00
{
Texture = skin.GetTexture("Menu/fountain-star") ?? textures.Get("Menu/fountain-star");
}
2023-07-13 19:31:00 +08:00
protected override FallingParticle CreateParticle()
{
return new FallingParticle
2023-07-13 19:31:00 +08:00
{
StartPosition = new Vector2(0, 50),
Duration = RNG.NextSingle(particle_duration_min, particle_duration_max),
StartAngle = getRandomVariance(4),
EndAngle = getRandomVariance(2),
2023-07-21 13:23:53 +08:00
EndScale = 2.2f + getRandomVariance(0.4f),
Velocity = new Vector2(getCurrentAngle(), -1400 + getRandomVariance(100)),
2023-07-13 19:31:00 +08:00
};
}
private float getCurrentAngle()
2023-07-13 19:31:00 +08:00
{
const float x_velocity_from_direction = 500;
const float x_velocity_random_variance = 60;
2023-07-13 19:31:00 +08:00
return lastShootDirection * x_velocity_from_direction * (float)(1 - 2 * (Clock.CurrentTime - lastShootTime!.Value) / shoot_duration) + getRandomVariance(x_velocity_random_variance);
}
2023-07-13 19:31:00 +08:00
private ScheduledDelegate? deactivateDelegate;
public void Shoot(int direction)
{
Active.Value = true;
deactivateDelegate?.Cancel();
deactivateDelegate = Scheduler.AddDelayed(() => Active.Value = false, shoot_duration);
lastShootTime = Clock.CurrentTime;
lastShootDirection = direction;
2023-07-13 19:31:00 +08:00
}
2023-07-13 22:12:29 +08:00
private static float getRandomVariance(float variance) => RNG.NextSingle(-variance, variance);
}
2023-07-13 19:31:00 +08:00
}
}