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