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;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Pooling;
|
|
|
|
using osu.Framework.Utils;
|
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 : CompositeDrawable
|
|
|
|
{
|
|
|
|
private DrawablePool<Star> starPool = null!;
|
|
|
|
private Container starContainer = null!;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
starPool = new DrawablePool<Star>(192),
|
|
|
|
starContainer = new Container()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Shoot()
|
|
|
|
{
|
2023-07-13 22:12:29 +08:00
|
|
|
// left centre or right movement.
|
|
|
|
int direction = RNG.Next(-1, 2);
|
2023-07-13 19:31:00 +08:00
|
|
|
|
2023-07-13 22:12:29 +08:00
|
|
|
const int total_stars = 192;
|
|
|
|
|
|
|
|
const float x_velocity_from_direction = 0.6f;
|
|
|
|
const float x_velocity_random_variance = 0.25f;
|
|
|
|
|
|
|
|
const float y_velocity_base = -2.0f;
|
|
|
|
const float y_velocity_random_variance = 0.25f;
|
|
|
|
|
|
|
|
const float x_spawn_position_variance = 10;
|
|
|
|
const float y_spawn_position_offset = 50;
|
|
|
|
|
|
|
|
for (int i = 0; i < total_stars; i++)
|
2023-07-13 19:31:00 +08:00
|
|
|
{
|
2023-07-13 22:12:29 +08:00
|
|
|
double initialOffset = i * 3;
|
2023-07-13 19:31:00 +08:00
|
|
|
|
|
|
|
starContainer.Add(starPool.Get(s =>
|
|
|
|
{
|
2023-07-13 22:12:29 +08:00
|
|
|
s.Velocity = new Vector2(
|
|
|
|
direction * x_velocity_from_direction + getRandomVariance(x_velocity_random_variance),
|
|
|
|
y_velocity_base + getRandomVariance(y_velocity_random_variance));
|
|
|
|
|
|
|
|
s.Position = new Vector2(getRandomVariance(x_spawn_position_variance), y_spawn_position_offset);
|
|
|
|
|
2023-07-13 19:31:00 +08:00
|
|
|
s.Hide();
|
|
|
|
|
2023-07-13 22:12:29 +08:00
|
|
|
using (s.BeginDelayedSequence(initialOffset))
|
2023-07-13 19:31:00 +08:00
|
|
|
{
|
|
|
|
double duration = RNG.Next(300, 1300);
|
|
|
|
|
2023-07-13 22:12:29 +08:00
|
|
|
s.ScaleTo(1)
|
|
|
|
.ScaleTo(RNG.NextSingle(1, 2.8f), duration, Easing.Out)
|
|
|
|
.FadeOutFromOne(duration, Easing.Out)
|
|
|
|
.Expire();
|
2023-07-13 19:31:00 +08:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private partial class Star : PoolableDrawable
|
|
|
|
{
|
|
|
|
public Vector2 Velocity = Vector2.Zero;
|
|
|
|
|
|
|
|
private float rotation;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2023-07-13 21:30:27 +08:00
|
|
|
private void load()
|
2023-07-13 19:31:00 +08:00
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2023-07-13 21:57:04 +08:00
|
|
|
new SkinnableSprite("Menu/fountain-star")
|
2023-07-13 19:31:00 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-07-13 22:12:29 +08:00
|
|
|
rotation = getRandomVariance(2);
|
2023-07-13 19:31:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
2023-07-13 22:12:29 +08:00
|
|
|
const float gravity = 0.003f;
|
2023-07-13 19:31:00 +08:00
|
|
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
float elapsed = (float)Time.Elapsed;
|
|
|
|
|
|
|
|
Position += Velocity * elapsed;
|
|
|
|
Velocity += new Vector2(0, elapsed * gravity);
|
|
|
|
|
|
|
|
Rotation += rotation * elapsed;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|