forked from ppy/osu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPippidonCharacter.cs
More file actions
88 lines (75 loc) · 2.88 KB
/
Copy pathPippidonCharacter.cs
File metadata and controls
88 lines (75 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// 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.Framework.Input.Events;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.Containers;
using System.Numerics;
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);
}
}
public bool OnPressed(KeyBindingPressEvent<PippidonAction> e)
{
switch (e.Action)
{
case PippidonAction.MoveUp:
changeLane(-1);
return true;
case PippidonAction.MoveDown:
changeLane(1);
return true;
default:
return false;
}
}
public void OnReleased(KeyBindingReleaseEvent<PippidonAction> e)
{
}
private void changeLane(int change) => LanePosition.Value = (LanePosition.Value + change + PippidonPlayfield.LANE_COUNT) % PippidonPlayfield.LANE_COUNT;
}
}