Combine triangle system implementations.

This commit is contained in:
Dean Herbert 2017-02-15 20:39:10 +09:00
parent 7fc035835b
commit 12e265a3e2
No known key found for this signature in database
GPG Key ID: 46D71BF4958ABB49
6 changed files with 61 additions and 65 deletions

View File

@ -14,9 +14,8 @@ namespace osu.Game.Modes.Osu.Objects.Drawables.Pieces
{
public class CirclePiece : Container
{
private Sprite disc;
private Triangles triangles;
public Func<bool> Hit;
@ -36,10 +35,11 @@ public CirclePiece()
Anchor = Anchor.Centre,
Origin = Anchor.Centre
},
triangles = new Triangles
new TrianglesPiece
{
RelativeSizeAxes = Axes.Both,
BlendingMode = BlendingMode.Additive,
RelativeSizeAxes = Axes.Both
Alpha = 0.5f,
}
};
}

View File

@ -21,10 +21,11 @@ public ExplodePiece()
Children = new Drawable[]
{
new Triangles
new TrianglesPiece
{
BlendingMode = BlendingMode.Additive,
RelativeSizeAxes = Axes.Both
RelativeSizeAxes = Axes.Both,
Alpha = 0.1f,
}
};
}

View File

@ -1,46 +0,0 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
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.Modes.Osu.Objects.Drawables.Pieces
{
public class Triangles : Container<Triangle>
{
public override bool HandleInput => false;
protected override void LoadComplete()
{
base.LoadComplete();
const float size = 100;
for (int i = 0; i < 10; i++)
{
Add(new Triangle
{
Origin = Anchor.Centre,
RelativePositionAxes = Axes.Both,
Position = new Vector2(RNG.NextSingle(), RNG.NextSingle()),
Scale = new Vector2(RNG.NextSingle() * 0.4f + 0.2f),
// Scaling height by 0.866 results in equiangular triangles (== 60° and equal side length)
Size = new Vector2(size, 0.866f * size),
Alpha = RNG.NextSingle() * 0.3f,
});
}
}
protected override void Update()
{
base.Update();
foreach (Drawable d in Children)
d.Position -= new Vector2(0, (float)(d.Scale.X * (Time.Elapsed / 2880)));
}
}
}

View File

@ -0,0 +1,26 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Game.Graphics.Backgrounds;
namespace osu.Game.Modes.Osu.Objects.Drawables.Pieces
{
public class TrianglesPiece : Triangles
{
protected override bool ExpireOffScreenTriangles => false;
protected override bool CreateNewTriangles => false;
protected override float SpawnRatio => 0.5f;
public TrianglesPiece()
{
TriangleScale = 1.2f;
}
protected override void Update()
{
if (IsPresent)
base.Update();
}
}
}

View File

@ -62,7 +62,7 @@
<Compile Include="Objects\Drawables\Pieces\RingPiece.cs" />
<Compile Include="Objects\Drawables\Pieces\SliderBouncer.cs" />
<Compile Include="Objects\Drawables\Pieces\SpinnerDisc.cs" />
<Compile Include="Objects\Drawables\Pieces\Triangles.cs" />
<Compile Include="Objects\Drawables\Pieces\TrianglesPiece.cs" />
<Compile Include="Objects\Drawables\Pieces\SliderBall.cs" />
<Compile Include="Objects\Drawables\Pieces\SliderBody.cs" />
<Compile Include="Objects\OsuHitObjectParser.cs" />

View File

@ -2,12 +2,10 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
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;
using OpenTK.Graphics;
@ -22,6 +20,21 @@ public class Triangles : Container<Triangle>
public Color4 ColourLight = Color4.White;
public Color4 ColourDark = Color4.Black;
/// <summary>
/// Whether we want to expire triangles as they exit our draw area completely.
/// </summary>
protected virtual bool ExpireOffScreenTriangles => true;
/// <summary>
/// Whether we should create new triangles as others expire.
/// </summary>
protected virtual bool CreateNewTriangles => true;
/// <summary>
/// The amount of triangles we want compared to the default distribution.
/// </summary>
protected virtual float SpawnRatio => 1;
private float triangleScale = 1;
public float TriangleScale
@ -29,9 +42,11 @@ public float TriangleScale
get { return triangleScale; }
set
{
float change = value / triangleScale;
triangleScale = value;
Children.ForEach(t => t.ScaleTo(triangleScale));
if (change != 1)
Children.ForEach(t => t.Scale *= change);
}
}
@ -42,20 +57,20 @@ protected override void LoadComplete()
addTriangle(true);
}
private int aimTriangleCount => (int)(DrawWidth * DrawHeight * 0.002f / (triangleScale * triangleScale));
private int aimTriangleCount => (int)(DrawWidth * DrawHeight * 0.002f / (triangleScale * triangleScale) * SpawnRatio);
protected override void Update()
{
base.Update();
foreach (Drawable d in Children)
foreach (var t in Children)
{
d.Position -= new Vector2(0, (float)(d.Scale.X * (50 / DrawHeight) * (Time.Elapsed / 950)) / triangleScale);
if (d.DrawPosition.Y + d.DrawSize.Y * d.Scale.Y < 0)
d.Expire();
t.Position -= new Vector2(0, (float)(t.Scale.X * (50 / DrawHeight) * (Time.Elapsed / 950)) / triangleScale);
if (ExpireOffScreenTriangles && t.DrawPosition.Y + t.DrawSize.Y * t.Scale.Y < 0)
t.Expire();
}
while (Children.Count() < aimTriangleCount)
while (CreateNewTriangles && Children.Count() < aimTriangleCount)
addTriangle(false);
}
@ -77,8 +92,8 @@ protected virtual Triangle CreateTriangle()
RelativePositionAxes = Axes.Both,
Scale = new Vector2(scale),
EdgeSmoothness = new Vector2(1),
// Scaling height by 0.866 results in equiangular triangles (== 60° and equal side length)
Colour = GetTriangleShade(),
// Scaling height by 0.866 results in equiangular triangles (== 60° and equal side length)
Size = new Vector2(size, 0.866f * size),
Depth = scale,
};
@ -89,8 +104,8 @@ protected virtual Triangle CreateTriangle()
private void addTriangle(bool randomY)
{
var sprite = CreateTriangle();
var triangleHeight = sprite.DrawHeight / DrawHeight;
sprite.Position = new Vector2(RNG.NextSingle(), randomY ? (RNG.NextSingle() * (1 + triangleHeight) - triangleHeight) : 1);
float triangleHeight = (sprite.DrawHeight / DrawHeight);
sprite.Position = new Vector2(RNG.NextSingle(), randomY ? RNG.NextSingle() * (1 + triangleHeight) - triangleHeight : 1);
Add(sprite);
}
}