From 622c90daf7f5a0d96b8f13f7d9079720df6cd625 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 28 Nov 2016 16:52:57 +0900 Subject: [PATCH] Add basic snaking. --- .../Objects/Drawables/DrawableSlider.cs | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/osu.Game.Mode.Osu/Objects/Drawables/DrawableSlider.cs b/osu.Game.Mode.Osu/Objects/Drawables/DrawableSlider.cs index b311e0b15f..13401eb6d3 100644 --- a/osu.Game.Mode.Osu/Objects/Drawables/DrawableSlider.cs +++ b/osu.Game.Mode.Osu/Objects/Drawables/DrawableSlider.cs @@ -1,4 +1,5 @@ -using osu.Framework.Graphics; +using System.Collections.Generic; +using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Osu.Objects.Drawables.Pieces; @@ -60,15 +61,14 @@ namespace osu.Game.Modes.Osu.Objects.Drawables { base.LoadComplete(); - for (int i = 0; i < slider.Curve.Length; i += 10) - path.Positions.Add(slider.Curve.PositionAt(i / slider.Curve.Length)); - path.PathWidth = startCircle.DrawWidth / 4; //force application of the state that was set before we loaded. UpdateState(State); } + double snakeDrawn = 0; + protected override void Update() { base.Update(); @@ -83,9 +83,30 @@ namespace osu.Game.Modes.Osu.Objects.Drawables if (currentRepeat % 2 == 1) t = 1 - t; } - - ball.Position = slider.Curve.PositionAt(t); + double snake = MathHelper.Clamp((Time.Current - slider.StartTime + 450) / 200, 0, 1); + if (snake != snakeDrawn) + { + if (snake < snakeDrawn) + { + //if we have gone backwards, just clear the path for now. + snakeDrawn = 0; + path.Positions.Clear(); + } + + const double segment_size = 10; + + while (snakeDrawn < snake) + { + snakeDrawn += segment_size; + path.Positions.Add(slider.Curve.PositionAt(snake)); + } + + snakeDrawn = snake; + path.Positions.Add(slider.Curve.PositionAt(snake)); + } + + ball.Position = slider.Curve.PositionAt(t); } protected override void UpdateState(ArmedState state)