mirror of
https://github.com/ppy/osu.git
synced 2024-12-28 13:32:56 +08:00
88 lines
2.8 KiB
C#
88 lines
2.8 KiB
C#
|
// 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;
|
||
|
using osu.Game.Beatmaps.ControlPoints;
|
||
|
using osu.Game.Graphics.Containers;
|
||
|
using osuTK;
|
||
|
|
||
|
namespace osu.Game.Rulesets.Pippidon.UI
|
||
|
{
|
||
|
public 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);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public bool OnPressed(PippidonAction action)
|
||
|
{
|
||
|
switch (action)
|
||
|
{
|
||
|
case PippidonAction.MoveUp:
|
||
|
changeLane(-1);
|
||
|
return true;
|
||
|
|
||
|
case PippidonAction.MoveDown:
|
||
|
changeLane(1);
|
||
|
return true;
|
||
|
|
||
|
default:
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void OnReleased(PippidonAction action)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
private void changeLane(int change) => LanePosition.Value = (LanePosition.Value + change + PippidonPlayfield.LANE_COUNT) % PippidonPlayfield.LANE_COUNT;
|
||
|
}
|
||
|
}
|