mirror of
https://github.com/ppy/osu.git
synced 2025-03-11 15:27:20 +08:00
initial implementation
This commit is contained in:
parent
c524b665ad
commit
10287e0150
75
osu.Game.Rulesets.Osu/Mods/OsuEaseHitObjectPositionsMod.cs
Normal file
75
osu.Game.Rulesets.Osu/Mods/OsuEaseHitObjectPositionsMod.cs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
// 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 System;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Utils;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
||||||
|
using osu.Game.Rulesets.Osu.UI;
|
||||||
|
using osu.Game.Rulesets.UI;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Osu.Mods
|
||||||
|
{
|
||||||
|
public abstract class OsuEaseHitObjectPositionsMod : Mod, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject>
|
||||||
|
{
|
||||||
|
public override ModType Type => ModType.Fun;
|
||||||
|
public override double ScoreMultiplier => 1;
|
||||||
|
public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay) };
|
||||||
|
|
||||||
|
protected BindableFloat EasementStrength = new BindableFloat(0.5f);
|
||||||
|
protected Vector2 CursorPosition;
|
||||||
|
protected DrawableHitObject WorkingHitObject;
|
||||||
|
protected abstract Vector2 DestinationVector { get; }
|
||||||
|
|
||||||
|
private IFrameStableClock gameplayClock;
|
||||||
|
|
||||||
|
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
|
||||||
|
{
|
||||||
|
gameplayClock = drawableRuleset.FrameStableClock;
|
||||||
|
|
||||||
|
// Hide judgment displays and follow points as they won't make any sense.
|
||||||
|
// Judgements can potentially be turned on in a future where they display at a position relative to their drawable counterpart.
|
||||||
|
drawableRuleset.Playfield.DisplayJudgements.Value = false;
|
||||||
|
(drawableRuleset.Playfield as OsuPlayfield)?.FollowPoints.Hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(Playfield playfield)
|
||||||
|
{
|
||||||
|
CursorPosition = playfield.Cursor.ActiveCursor.DrawPosition;
|
||||||
|
|
||||||
|
foreach (var drawable in playfield.HitObjectContainer.AliveObjects)
|
||||||
|
{
|
||||||
|
WorkingHitObject = drawable;
|
||||||
|
switch (drawable)
|
||||||
|
{
|
||||||
|
case DrawableHitCircle circle:
|
||||||
|
easeHitObjectPositionToVector(circle, DestinationVector);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DrawableSlider slider:
|
||||||
|
|
||||||
|
if (!slider.HeadCircle.Result.HasResult)
|
||||||
|
easeHitObjectPositionToVector(slider, DestinationVector);
|
||||||
|
else
|
||||||
|
easeHitObjectPositionToVector(slider, DestinationVector - slider.Ball.DrawPosition);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void easeHitObjectPositionToVector(DrawableHitObject hitObject, Vector2 destination)
|
||||||
|
{
|
||||||
|
double dampLength = Interpolation.Lerp(3000, 40, EasementStrength.Value);
|
||||||
|
|
||||||
|
float x = (float)Interpolation.DampContinuously(hitObject.X, Math.Clamp(destination.X, 0, OsuPlayfield.BASE_SIZE.X), dampLength, gameplayClock.ElapsedFrameTime);
|
||||||
|
float y = (float)Interpolation.DampContinuously(hitObject.Y, Math.Clamp(destination.Y, 0, OsuPlayfield.BASE_SIZE.Y), dampLength, gameplayClock.ElapsedFrameTime);
|
||||||
|
|
||||||
|
hitObject.Position = new Vector2(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,31 +2,23 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Utils;
|
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Rulesets.Mods;
|
|
||||||
using osu.Game.Rulesets.Objects.Drawables;
|
|
||||||
using osu.Game.Rulesets.Osu.Objects;
|
|
||||||
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
|
||||||
using osu.Game.Rulesets.Osu.UI;
|
|
||||||
using osu.Game.Rulesets.UI;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Osu.Mods
|
namespace osu.Game.Rulesets.Osu.Mods
|
||||||
{
|
{
|
||||||
internal class OsuModMagnetised : Mod, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject>
|
internal class OsuModMagnetised : OsuEaseHitObjectPositionsMod
|
||||||
{
|
{
|
||||||
public override string Name => "Magnetised";
|
public override string Name => "Magnetised";
|
||||||
public override string Acronym => "MG";
|
public override string Acronym => "MG";
|
||||||
public override IconUsage? Icon => FontAwesome.Solid.Magnet;
|
public override IconUsage? Icon => FontAwesome.Solid.Magnet;
|
||||||
public override ModType Type => ModType.Fun;
|
|
||||||
public override string Description => "No need to chase the circles – your cursor is a magnet!";
|
public override string Description => "No need to chase the circles – your cursor is a magnet!";
|
||||||
public override double ScoreMultiplier => 1;
|
public override Type[] IncompatibleMods => base.IncompatibleMods.Concat(new[] { typeof(OsuModRelax), typeof(OsuModRepel) }).ToArray();
|
||||||
public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay), typeof(OsuModRelax) };
|
|
||||||
|
|
||||||
private IFrameStableClock gameplayClock;
|
protected override Vector2 DestinationVector => CursorPosition;
|
||||||
|
|
||||||
[SettingSource("Attraction strength", "How strong the pull is.", 0)]
|
[SettingSource("Attraction strength", "How strong the pull is.", 0)]
|
||||||
public BindableFloat AttractionStrength { get; } = new BindableFloat(0.5f)
|
public BindableFloat AttractionStrength { get; } = new BindableFloat(0.5f)
|
||||||
@ -36,48 +28,9 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
MaxValue = 1.0f,
|
MaxValue = 1.0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
|
public OsuModMagnetised()
|
||||||
{
|
{
|
||||||
gameplayClock = drawableRuleset.FrameStableClock;
|
EasementStrength.BindTo(AttractionStrength);
|
||||||
|
|
||||||
// Hide judgment displays and follow points as they won't make any sense.
|
|
||||||
// Judgements can potentially be turned on in a future where they display at a position relative to their drawable counterpart.
|
|
||||||
drawableRuleset.Playfield.DisplayJudgements.Value = false;
|
|
||||||
(drawableRuleset.Playfield as OsuPlayfield)?.FollowPoints.Hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(Playfield playfield)
|
|
||||||
{
|
|
||||||
var cursorPos = playfield.Cursor.ActiveCursor.DrawPosition;
|
|
||||||
|
|
||||||
foreach (var drawable in playfield.HitObjectContainer.AliveObjects)
|
|
||||||
{
|
|
||||||
switch (drawable)
|
|
||||||
{
|
|
||||||
case DrawableHitCircle circle:
|
|
||||||
easeTo(circle, cursorPos);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DrawableSlider slider:
|
|
||||||
|
|
||||||
if (!slider.HeadCircle.Result.HasResult)
|
|
||||||
easeTo(slider, cursorPos);
|
|
||||||
else
|
|
||||||
easeTo(slider, cursorPos - slider.Ball.DrawPosition);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void easeTo(DrawableHitObject hitObject, Vector2 destination)
|
|
||||||
{
|
|
||||||
double dampLength = Interpolation.Lerp(3000, 40, AttractionStrength.Value);
|
|
||||||
|
|
||||||
float x = (float)Interpolation.DampContinuously(hitObject.X, destination.X, dampLength, gameplayClock.ElapsedFrameTime);
|
|
||||||
float y = (float)Interpolation.DampContinuously(hitObject.Y, destination.Y, dampLength, gameplayClock.ElapsedFrameTime);
|
|
||||||
|
|
||||||
hitObject.Position = new Vector2(x, y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
39
osu.Game.Rulesets.Osu/Mods/OsuModRepel.cs
Normal file
39
osu.Game.Rulesets.Osu/Mods/OsuModRepel.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// 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 System;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Configuration;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Osu.Mods
|
||||||
|
{
|
||||||
|
internal class OsuModRepel : OsuEaseHitObjectPositionsMod
|
||||||
|
{
|
||||||
|
public override string Name => "Repel";
|
||||||
|
public override string Acronym => "RP";
|
||||||
|
public override IconUsage? Icon => FontAwesome.Solid.ExpandArrowsAlt;
|
||||||
|
public override string Description => "Run away!";
|
||||||
|
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(OsuModMagnetised)).ToArray();
|
||||||
|
|
||||||
|
[SettingSource("Repulsion strength", "How strong the repulsion is.", 0)]
|
||||||
|
public BindableFloat RepulsionStrength { get; } = new BindableFloat(0.5f)
|
||||||
|
{
|
||||||
|
Precision = 0.05f,
|
||||||
|
MinValue = 0.05f,
|
||||||
|
MaxValue = 1.0f,
|
||||||
|
};
|
||||||
|
|
||||||
|
protected override Vector2 DestinationVector => new Vector2(
|
||||||
|
2 * WorkingHitObject.X - CursorPosition.X,
|
||||||
|
2 * WorkingHitObject.Y - CursorPosition.Y
|
||||||
|
);
|
||||||
|
|
||||||
|
public OsuModRepel()
|
||||||
|
{
|
||||||
|
EasementStrength.BindTo(RepulsionStrength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -195,7 +195,7 @@ namespace osu.Game.Rulesets.Osu
|
|||||||
new OsuModApproachDifferent(),
|
new OsuModApproachDifferent(),
|
||||||
new OsuModMuted(),
|
new OsuModMuted(),
|
||||||
new OsuModNoScope(),
|
new OsuModNoScope(),
|
||||||
new OsuModMagnetised(),
|
new MultiMod(new OsuModMagnetised(), new OsuModRepel()),
|
||||||
new ModAdaptiveSpeed()
|
new ModAdaptiveSpeed()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user