Esempio n. 1
0
        private IEnumerator moveBetweenNodes(Entity entity, MarioClearPipeInteraction interaction, Vector2 from, Vector2 to, float?travelSpeed = null, bool?lerpPipeOffset = null)
        {
            interaction.Distance = (from - to).Length();

            interaction.DirectionVector = GetPipeExitDirectionVector(to, from);
            interaction.Direction       = GetPipeExitDirection(to, from);

            interaction.From = from;
            interaction.To   = to;

            interaction.TravelSpeed    = travelSpeed != null ? travelSpeed.Value : interaction.TravelSpeed;
            interaction.LerpPipeOffset = lerpPipeOffset != null ? lerpPipeOffset.Value : interaction.LerpPipeOffset;

            while (entity != null && interaction.Moved <= interaction.Distance && interaction.Distance != 0f && !interaction.ExitEarly)
            {
                interaction?.OnPipeUpdate(entity, interaction);

                float lerpValue = interaction.Moved / interaction.Distance;

                entity.Position    = Vector2.Lerp(from, to, lerpValue) + (interaction.LerpPipeOffset ? Vector2.Lerp(Vector2.Zero, interaction.PipeRenderOffset, lerpValue) : interaction.PipeRenderOffset);
                interaction.Moved += interaction.TravelSpeed * Engine.DeltaTime;

                yield return(null);
            }

            interaction.Moved -= interaction.Distance;
        }