2016-12-01 17:53:13 +08:00
|
|
|
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
2016-12-01 19:21:14 +08:00
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2016-12-01 17:53:13 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
using osu.Framework.MathUtils;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Backgrounds
|
|
|
|
|
{
|
2016-12-02 02:12:35 +08:00
|
|
|
|
public class Triangles : Container<Triangle>
|
2016-12-01 17:53:13 +08:00
|
|
|
|
{
|
2016-12-15 20:47:32 +08:00
|
|
|
|
public override bool HandleInput => false;
|
|
|
|
|
|
2016-12-01 17:53:13 +08:00
|
|
|
|
public Triangles()
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0.3f;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 19:21:14 +08:00
|
|
|
|
private float triangleScale = 1;
|
|
|
|
|
|
|
|
|
|
public float TriangleScale
|
|
|
|
|
{
|
|
|
|
|
get { return triangleScale; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
triangleScale = value;
|
|
|
|
|
|
|
|
|
|
Children.ForEach(t => t.ScaleTo(triangleScale));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int aimTriangleCount => (int)((DrawWidth * DrawHeight) / 800 / triangleScale);
|
2016-12-01 17:53:13 +08:00
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
foreach (Drawable d in Children)
|
|
|
|
|
{
|
2016-12-01 19:21:14 +08:00
|
|
|
|
d.Position -= new Vector2(0, (float)(d.Scale.X * (50 / DrawHeight) * (Time.Elapsed / 880)) / triangleScale);
|
2016-12-01 17:53:13 +08:00
|
|
|
|
if (d.DrawPosition.Y + d.DrawSize.Y * d.Scale.Y < 0)
|
|
|
|
|
d.Expire();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool useRandomX = Children.Count() < aimTriangleCount / 2;
|
|
|
|
|
while (Children.Count() < aimTriangleCount)
|
|
|
|
|
addTriangle(useRandomX);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 02:12:35 +08:00
|
|
|
|
protected virtual Triangle CreateTriangle()
|
2016-12-01 17:53:13 +08:00
|
|
|
|
{
|
2016-12-01 19:21:14 +08:00
|
|
|
|
var scale = triangleScale * RNG.NextSingle() * 0.4f + 0.2f;
|
2016-12-02 02:12:35 +08:00
|
|
|
|
const float size = 100;
|
2016-12-01 19:21:14 +08:00
|
|
|
|
|
2016-12-02 02:12:35 +08:00
|
|
|
|
return new Triangle
|
2016-12-01 17:53:13 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
RelativePositionAxes = Axes.Both,
|
2016-12-01 19:21:14 +08:00
|
|
|
|
Scale = new Vector2(scale),
|
2016-12-02 02:12:35 +08:00
|
|
|
|
// Scaling height by 0.866 results in equiangular triangles (== 60° and equal side length)
|
|
|
|
|
Size = new Vector2(size, 0.866f * size),
|
2016-12-01 19:21:14 +08:00
|
|
|
|
Alpha = RNG.NextSingle(),
|
|
|
|
|
Depth = scale,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addTriangle(bool randomX)
|
|
|
|
|
{
|
|
|
|
|
var sprite = CreateTriangle();
|
|
|
|
|
sprite.Position = new Vector2(RNG.NextSingle(), randomX ? RNG.NextSingle() : 1);
|
|
|
|
|
Add(sprite);
|
2016-12-01 17:53:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|