1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 10:32:55 +08:00
osu-lazer/Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/UI/PippidonCharacter.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

89 lines
2.9 KiB
C#
Raw Normal View History

2021-04-05 10:41:40 +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.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Bindings;
2021-09-16 17:26:12 +08:00
using osu.Framework.Input.Events;
2021-04-05 10:41:40 +08:00
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.Containers;
using osuTK;
namespace osu.Game.Rulesets.Pippidon.UI
{
public partial class PippidonCharacter : BeatSyncedContainer, IKeyBindingHandler<PippidonAction>
{
public readonly BindableInt LanePosition = new BindableInt
{
Value = 0,
MinValue = 0,
MaxValue = PippidonPlayfield.LANE_COUNT - 1,
};
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
Size = new Vector2(PippidonPlayfield.LANE_HEIGHT);
Child = new Sprite
{
FillMode = FillMode.Fit,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(1.2f),
RelativeSizeAxes = Axes.Both,
Texture = textures.Get("character")
};
LanePosition.BindValueChanged(e => { this.MoveToY(e.NewValue * PippidonPlayfield.LANE_HEIGHT); });
}
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes)
{
if (effectPoint.KiaiMode)
{
bool direction = beatIndex % 2 == 1;
double duration = timingPoint.BeatLength / 2;
Child.RotateTo(direction ? 10 : -10, duration * 2, Easing.InOutSine);
Child.Animate(i => i.MoveToY(-10, duration, Easing.Out))
.Then(i => i.MoveToY(0, duration, Easing.In));
}
else
{
Child.ClearTransforms();
Child.RotateTo(0, 500, Easing.Out);
Child.MoveTo(Vector2.Zero, 500, Easing.Out);
}
}
2021-09-16 17:26:12 +08:00
public bool OnPressed(KeyBindingPressEvent<PippidonAction> e)
2021-04-05 10:41:40 +08:00
{
2021-09-16 17:26:12 +08:00
switch (e.Action)
2021-04-05 10:41:40 +08:00
{
case PippidonAction.MoveUp:
changeLane(-1);
return true;
case PippidonAction.MoveDown:
changeLane(1);
return true;
default:
return false;
}
}
2021-09-16 17:26:12 +08:00
public void OnReleased(KeyBindingReleaseEvent<PippidonAction> e)
2021-04-05 10:41:40 +08:00
{
}
private void changeLane(int change) => LanePosition.Value = (LanePosition.Value + change + PippidonPlayfield.LANE_COUNT) % PippidonPlayfield.LANE_COUNT;
}
}