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

278 lines
12 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2018-01-03 17:26:54 +08:00
using System;
2016-11-14 17:03:20 +08:00
using osu.Framework.Allocation;
2018-01-03 17:26:54 +08:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
2017-08-03 07:32:38 +08:00
using osu.Framework.Graphics.Containers;
2017-12-31 21:09:07 +08:00
using osu.Framework.Graphics.Shapes;
2018-01-03 19:52:11 +08:00
using osu.Framework.MathUtils;
2017-10-10 15:34:01 +08:00
using osu.Game.Rulesets.Catch.Objects.Drawable.Pieces;
using OpenTK;
using OpenTK.Graphics;
2017-04-18 15:05:58 +08:00
namespace osu.Game.Rulesets.Catch.Objects.Drawable
{
public class DrawableFruit : PalpableCatchHitObject<Fruit>
{
2017-12-31 21:09:07 +08:00
private Circle border;
2017-10-10 15:34:01 +08:00
public DrawableFruit(Fruit h)
2017-08-08 11:46:37 +08:00
: base(h)
{
Origin = Anchor.Centre;
2018-01-03 17:26:54 +08:00
Size = new Vector2((float)CatchHitObject.OBJECT_RADIUS);
AccentColour = HitObject.ComboColour;
Masking = false;
2017-10-10 15:34:01 +08:00
2018-01-03 19:52:11 +08:00
Rotation = (float)(RNG.NextDouble() - 0.5f) * 40;
}
[BackgroundDependencyLoader]
private void load()
{
2018-01-03 17:26:54 +08:00
Children = new[]
{
2018-01-03 17:26:54 +08:00
createPulp(HitObject.VisualRepresentation),
2017-12-31 21:09:07 +08:00
border = new Circle
{
2018-01-03 17:26:54 +08:00
EdgeEffect = new EdgeEffectParameters
{
2018-01-03 19:55:52 +08:00
Hollow = !HitObject.HyperDash,
2018-01-03 17:26:54 +08:00
Type = EdgeEffectType.Glow,
Radius = 4,
2018-01-03 19:55:52 +08:00
Colour = HitObject.HyperDash ? Color4.Red : AccentColour.Darken(1).Opacity(0.6f)
2018-01-03 17:26:54 +08:00
},
Size = new Vector2(Height * 1.5f),
2017-12-31 21:09:07 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2018-01-03 17:26:54 +08:00
BorderColour = Color4.White,
BorderThickness = 4f,
2017-12-31 21:09:07 +08:00
Children = new Framework.Graphics.Drawable[]
{
new Box
{
AlwaysPresent = true,
Colour = AccentColour,
Alpha = 0,
RelativeSizeAxes = Axes.Both
}
}
},
};
if (HitObject.HyperDash)
{
Add(new Pulp
{
RelativePositionAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AccentColour = Color4.Red,
Blending = BlendingMode.Additive,
Alpha = 0.5f,
2018-01-03 17:26:54 +08:00
Scale = new Vector2(1.333f)
});
}
}
2017-12-31 21:09:07 +08:00
2018-01-03 17:26:54 +08:00
private Framework.Graphics.Drawable createPulp(FruitVisualRepresentation representation)
{
const float large_pulp_3 = 13f;
const float distance_from_centre_3 = 0.23f;
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;
Vector2 positionAt(float angle, float distance) => new Vector2(
distance * (float)Math.Sin(angle * Math.PI / 180),
distance * (float)Math.Cos(angle * Math.PI / 180));
switch (representation)
{
default:
2018-01-03 19:55:52 +08:00
return new Container();
2018-01-04 17:20:23 +08:00
case FruitVisualRepresentation.Raspberry:
2018-01-03 17:26:54 +08:00
return new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Framework.Graphics.Drawable[]
{
new Pulp
{
Anchor = Anchor.TopCentre,
Origin = Anchor.BottomCentre,
AccentColour = AccentColour,
Size = new Vector2(small_pulp),
Y = 0.05f,
},
new Pulp
{
AccentColour = AccentColour,
Size = new Vector2(large_pulp_4),
Position = positionAt(0, distance_from_centre_4),
},
new Pulp
{
AccentColour = AccentColour,
Size = new Vector2(large_pulp_4),
Position = positionAt(90, distance_from_centre_4),
},
new Pulp
{
AccentColour = AccentColour,
Size = new Vector2(large_pulp_4),
Position = positionAt(180, distance_from_centre_4),
},
new Pulp
{
Size = new Vector2(large_pulp_4),
AccentColour = AccentColour,
Position = positionAt(270, distance_from_centre_4),
},
}
};
case FruitVisualRepresentation.Pineapple:
return new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Framework.Graphics.Drawable[]
{
new Pulp
{
Anchor = Anchor.TopCentre,
Origin = Anchor.BottomCentre,
AccentColour = AccentColour,
Size = new Vector2(small_pulp),
Y = 0.1f,
},
new Pulp
{
AccentColour = AccentColour,
Size = new Vector2(large_pulp_4),
Position = positionAt(45, distance_from_centre_4),
},
new Pulp
{
AccentColour = AccentColour,
Size = new Vector2(large_pulp_4),
Position = positionAt(135, distance_from_centre_4),
},
new Pulp
{
AccentColour = AccentColour,
Size = new Vector2(large_pulp_4),
Position = positionAt(225, distance_from_centre_4),
},
new Pulp
{
Size = new Vector2(large_pulp_4),
AccentColour = AccentColour,
Position = positionAt(315, distance_from_centre_4),
},
}
};
2018-01-04 17:20:23 +08:00
case FruitVisualRepresentation.Pear:
2018-01-03 17:26:54 +08:00
return new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Framework.Graphics.Drawable[]
{
new Pulp
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AccentColour = AccentColour,
Size = new Vector2(small_pulp),
Y = -0.1f,
},
new Pulp
{
AccentColour = AccentColour,
Size = new Vector2(large_pulp_3),
Position = positionAt(60, distance_from_centre_3),
},
new Pulp
{
AccentColour = AccentColour,
Size = new Vector2(large_pulp_3),
Position = positionAt(180, distance_from_centre_3),
},
new Pulp
{
Size = new Vector2(large_pulp_3),
AccentColour = AccentColour,
Position = positionAt(300, distance_from_centre_3),
},
}
};
case FruitVisualRepresentation.Grape:
return new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Framework.Graphics.Drawable[]
{
new Pulp
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AccentColour = AccentColour,
Size = new Vector2(small_pulp),
},
new Pulp
{
AccentColour = AccentColour,
Size = new Vector2(large_pulp_3),
Position = positionAt(0, distance_from_centre_3),
},
new Pulp
{
AccentColour = AccentColour,
Size = new Vector2(large_pulp_3),
Position = positionAt(120, distance_from_centre_3),
},
new Pulp
{
Size = new Vector2(large_pulp_3),
AccentColour = AccentColour,
Position = positionAt(240, distance_from_centre_3),
},
}
};
case FruitVisualRepresentation.Banana:
return new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Framework.Graphics.Drawable[]
{
new Pulp
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AccentColour = AccentColour,
Size = new Vector2(small_pulp),
Y = -0.15f
},
new Pulp
{
AccentColour = AccentColour,
Size = new Vector2(large_pulp_4 * 1.2f, large_pulp_4 * 3),
},
}
};
2018-01-03 17:26:54 +08:00
}
}
2017-12-31 21:09:07 +08:00
protected override void Update()
{
base.Update();
border.Alpha = (float)MathHelper.Clamp((HitObject.StartTime - Time.Current) / 500, 0, 1);
2017-12-31 21:09:07 +08:00
}
}
}