1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 11:03:22 +08:00
osu-lazer/osu.Game.Rulesets.Catch/Objects/Drawable/DrawableFruit.cs

317 lines
12 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
using System;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-04-02 13:51:28 +08:00
using osu.Framework.Graphics.Effects;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics.Shapes;
2020-01-09 12:43:44 +08:00
using osu.Framework.Utils;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Catch.Objects.Drawable.Pieces;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Catch.Objects.Drawable
{
public class DrawableFruit : PalpableCatchHitObject<Fruit>
{
private Circle border;
private const float drawable_radius = (float)CatchHitObject.OBJECT_RADIUS * radius_adjust;
/// <summary>
/// Because we're adding a border around the fruit, we need to scale down some.
/// </summary>
private const float radius_adjust = 1.1f;
2018-04-13 17:19:50 +08:00
public DrawableFruit(Fruit h)
: base(h)
{
Origin = Anchor.Centre;
Size = new Vector2(drawable_radius);
2018-04-13 17:19:50 +08:00
Masking = false;
Rotation = (float)(RNG.NextDouble() - 0.5f) * 40;
}
[BackgroundDependencyLoader]
private void load()
{
// todo: this should come from the skin.
2019-07-22 13:45:25 +08:00
AccentColour.Value = colourForRepresentation(HitObject.VisualRepresentation);
2018-04-13 17:19:50 +08:00
AddRangeInternal(new[]
2018-04-13 17:19:50 +08:00
{
createPulp(HitObject.VisualRepresentation),
border = new Circle
{
EdgeEffect = new EdgeEffectParameters
{
Hollow = !HitObject.HyperDash,
Type = EdgeEffectType.Glow,
Radius = 4 * radius_adjust,
2019-07-22 13:45:25 +08:00
Colour = HitObject.HyperDash ? Color4.Red : AccentColour.Value.Darken(1).Opacity(0.6f)
2018-04-13 17:19:50 +08:00
},
Size = new Vector2(Height),
2018-04-13 17:19:50 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
BorderColour = Color4.White,
BorderThickness = 3f * radius_adjust,
2018-04-13 17:19:50 +08:00
Children = new Framework.Graphics.Drawable[]
{
new Box
{
AlwaysPresent = true,
2019-07-22 13:45:25 +08:00
Colour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Alpha = 0,
RelativeSizeAxes = Axes.Both
}
}
},
});
2018-04-13 17:19:50 +08:00
if (HitObject.HyperDash)
{
AddInternal(new Pulp
{
RelativePositionAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AccentColour = Color4.Red,
2019-08-21 12:29:50 +08:00
Blending = BlendingParameters.Additive,
2018-04-13 17:19:50 +08:00
Alpha = 0.5f,
Scale = new Vector2(1.333f)
});
}
}
private Framework.Graphics.Drawable createPulp(FruitVisualRepresentation representation)
{
const float large_pulp_3 = 8f * radius_adjust;
const float distance_from_centre_3 = 0.15f;
2018-04-13 17:19:50 +08:00
const float large_pulp_4 = large_pulp_3 * 0.925f;
const float distance_from_centre_4 = distance_from_centre_3 / 0.925f;
const float small_pulp = large_pulp_3 / 2;
2019-11-12 18:37:20 +08:00
static Vector2 positionAt(float angle, float distance) => new Vector2(
distance * MathF.Sin(angle * MathF.PI / 180),
distance * MathF.Cos(angle * MathF.PI / 180));
2018-04-13 17:19:50 +08:00
switch (representation)
{
default:
return new Container();
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
case FruitVisualRepresentation.Raspberry:
return new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Framework.Graphics.Drawable[]
{
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Size = new Vector2(small_pulp),
Y = -0.34f,
2018-04-13 17:19:50 +08:00
},
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Size = new Vector2(large_pulp_4),
Position = positionAt(0, distance_from_centre_4),
},
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Size = new Vector2(large_pulp_4),
Position = positionAt(90, distance_from_centre_4),
},
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Size = new Vector2(large_pulp_4),
Position = positionAt(180, distance_from_centre_4),
},
new Pulp
{
Size = new Vector2(large_pulp_4),
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Position = positionAt(270, distance_from_centre_4),
},
}
};
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
case FruitVisualRepresentation.Pineapple:
return new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Framework.Graphics.Drawable[]
{
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Size = new Vector2(small_pulp),
Y = -0.3f,
2018-04-13 17:19:50 +08:00
},
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Size = new Vector2(large_pulp_4),
Position = positionAt(45, distance_from_centre_4),
},
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Size = new Vector2(large_pulp_4),
Position = positionAt(135, distance_from_centre_4),
},
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Size = new Vector2(large_pulp_4),
Position = positionAt(225, distance_from_centre_4),
},
new Pulp
{
Size = new Vector2(large_pulp_4),
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Position = positionAt(315, distance_from_centre_4),
},
}
};
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
case FruitVisualRepresentation.Pear:
return new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Framework.Graphics.Drawable[]
{
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Size = new Vector2(small_pulp),
Y = -0.33f,
2018-04-13 17:19:50 +08:00
},
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Size = new Vector2(large_pulp_3),
Position = positionAt(60, distance_from_centre_3),
},
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Size = new Vector2(large_pulp_3),
Position = positionAt(180, distance_from_centre_3),
},
new Pulp
{
Size = new Vector2(large_pulp_3),
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Position = positionAt(300, distance_from_centre_3),
},
}
};
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
case FruitVisualRepresentation.Grape:
return new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Framework.Graphics.Drawable[]
{
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Size = new Vector2(small_pulp),
Y = -0.25f,
2018-04-13 17:19:50 +08:00
},
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Size = new Vector2(large_pulp_3),
Position = positionAt(0, distance_from_centre_3),
},
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Size = new Vector2(large_pulp_3),
Position = positionAt(120, distance_from_centre_3),
},
new Pulp
{
Size = new Vector2(large_pulp_3),
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Position = positionAt(240, distance_from_centre_3),
},
}
};
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
case FruitVisualRepresentation.Banana:
return new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Framework.Graphics.Drawable[]
{
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
2018-04-13 17:19:50 +08:00
Size = new Vector2(small_pulp),
Y = -0.3f
2018-04-13 17:19:50 +08:00
},
new Pulp
{
2019-07-22 13:45:25 +08:00
AccentColour = AccentColour.Value,
Size = new Vector2(large_pulp_4 * 0.8f, large_pulp_4 * 2.5f),
Y = 0.05f,
2018-04-13 17:19:50 +08:00
},
}
};
}
}
protected override void Update()
{
base.Update();
border.Alpha = (float)Math.Clamp((HitObject.StartTime - Time.Current) / 500, 0, 1);
2018-04-13 17:19:50 +08:00
}
private Color4 colourForRepresentation(FruitVisualRepresentation representation)
2018-04-13 17:19:50 +08:00
{
switch (representation)
{
default:
case FruitVisualRepresentation.Pear:
return new Color4(17, 136, 170, 255);
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
case FruitVisualRepresentation.Grape:
return new Color4(204, 102, 0, 255);
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
case FruitVisualRepresentation.Raspberry:
return new Color4(121, 9, 13, 255);
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
case FruitVisualRepresentation.Pineapple:
return new Color4(102, 136, 0, 255);
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
case FruitVisualRepresentation.Banana:
switch (RNG.Next(0, 3))
{
default:
return new Color4(255, 240, 0, 255);
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
case 1:
return new Color4(255, 192, 0, 255);
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
case 2:
return new Color4(214, 221, 28, 255);
}
}
}
}
}