Esempio n. 1
0
 private void OnLoseLeader()
 {
     if (!_collected && ReturnHomeWhenLost)
     {
         Alarm.Set(this, 0.15f, delegate
         {
             RustBerry strawberry = this;
             Vector2 vector       = (_start - Position).SafeNormalize();
             float num            = Vector2.Distance(Position, _start);
             float scaleFactor    = Calc.ClampedMap(num, 16f, 120f, 16f, 96f);
             Vector2 control      = _start + vector * 16f + vector.Perpendicular() * scaleFactor * Calc.Random.Choose(1, -1);
             SimpleCurve curve    = new SimpleCurve(Position, _start, control);
             Tween tween          = Tween.Create(Tween.TweenMode.Oneshot, Ease.SineOut, MathHelper.Max(num / 100f, 0.4f), start: true);
             tween.OnUpdate       = delegate(Tween f)
             {
                 strawberry.Position = curve.GetPoint(f.Eased);
             };
             tween.OnComplete = delegate
             {
                 Depth = 0;
             };
             Add(tween);
         });
     }
 }
Esempio n. 2
0
        public IEnumerator UseRoutine(Vector2 target)
        {
            Turning = true;
            follower.MoveTowardsLeader = false;
            wiggler.Start();
            wobbleActive = false;
            sprite.Y     = 0f;
            Vector2     from  = Position;
            SimpleCurve curve = new SimpleCurve(from, target, (target + from) / 2f + new Vector2(0f, -48f));

            tween          = Tween.Create(Tween.TweenMode.Oneshot, Ease.CubeOut, 1f, start: true);
            tween.OnUpdate = delegate(Tween t)
            {
                Position    = curve.GetPoint(t.Eased);
                sprite.Rate = 1f + t.Eased * 2f;
            };
            Add(tween);
            yield return(tween.Wait());

            tween = null;
            while (sprite.CurrentAnimationFrame != 0)
            {
                yield return(null);
            }
            shimmerParticles.Active = false;
            Input.Rumble(RumbleStrength.Medium, RumbleLength.Medium);
            for (int j = 0; j < 16; j++)
            {
                SceneAs <Level>().ParticlesFG.Emit(P_Insert, Center, (float)Math.PI / 8f * (float)j);
            }
            sprite.Visible = false;
            light.Visible  = false;
            Turning        = false;
        }
Esempio n. 3
0
        private IEnumerator MoveOnCurve(Vector2 from, Vector2 anchor, Vector2 to) {
            SimpleCurve curve = new SimpleCurve(from, to, anchor);
            var duration = curve.GetLengthParametric(32) / 500f;
            Vector2 was = from;
            for (var t = 0.016f; t <= 1f; t += Engine.DeltaTime / duration) {
                Position = curve.GetPoint(t).Floor();
                sprite.Rotation = Calc.Angle(curve.GetPoint(Math.Max(0f, t - 0.05f)),
                    curve.GetPoint(Math.Min(1f, t + 0.05f)));
                // sprite.Scale.X = 1.25f;
                sprite.Scale.X = -1.25f;
                sprite.Scale.Y = 0.7f;
                if ((was - Position).Length() > 32f) {
                    TrailManager.Add(this, trailColor, 1f, false);
                    was = Position;
                }

                yield return null;
            }

            Position = to;
        }
Esempio n. 4
0
        private IEnumerator MoveNumberCoroutine(Vector2 start, Vector2 end)
        {
            yield return(.4f);

            SimpleCurve curve = new SimpleCurve(start, end, (start + end) / 2f + new Vector2(0f, 48f));

            for (float t = 0f; t < 1f; t += Engine.DeltaTime)
            {
                yield return(null);

                Position = curve.GetPoint(Ease.CubeInOut(t));
            }
        }
 private void OnLoseLeader()
 {
     if (!collected && ReturnHomeWhenLost)
     {
         Alarm.Set(this, 0.15f, delegate {
             Vector2 displacement = (start - Position).SafeNormalize();
             float dist           = Vector2.Distance(Position, start);
             float scaleFactor    = Calc.ClampedMap(dist, 16f, 120f, 16f, 96f);
             Vector2 control      = start + displacement * 16f + displacement.Perpendicular() * scaleFactor * Calc.Random.Choose(1, -1);
             SimpleCurve curve    = new SimpleCurve(Position, start, control);
             Tween tween          = Tween.Create(Tween.TweenMode.Oneshot, Ease.SineOut, MathHelper.Max(dist / 100f, 0.4f), start: true);
             tween.OnUpdate       = delegate(Tween f) {
                 Position = curve.GetPoint(f.Eased);
             };
             tween.OnComplete = delegate {
                 Depth = 0;
             };
             Add(tween);
         });
     }
 }
Esempio n. 6
0
        // When the Strawberry's Follower loses its Leader (basically, when you die),
        // the Strawberry performs this action to smoothly return home.
        // If you detach a Strawberry and need it to be collectable again,
        // make sure to re-enable its collision in tween.OnComplete's delegate.
        private void OnLoseLeader()
        {
            if (collected)
            {
                return;
            }

            Alarm.Set(this, 0.15f, delegate {
                Vector2 vector    = (start - Position).SafeNormalize();
                float num         = Vector2.Distance(Position, start);
                float scaleFactor = Calc.ClampedMap(num, 16f, 120f, 16f, 96f);
                Vector2 control   = start + vector * 16f + vector.Perpendicular() * scaleFactor * (float)Calc.Random.Choose(1, -1);
                SimpleCurve curve = new SimpleCurve(Position, start, control);
                Tween tween       = Tween.Create(Tween.TweenMode.Oneshot, Ease.SineOut, MathHelper.Max(num / 100f, 0.4f), true);
                tween.OnUpdate    = delegate(Tween f) {
                    Position = curve.GetPoint(f.Eased);
                };
                tween.OnComplete = delegate(Tween f) {
                    Depth = 0;
                };
                Add(tween);
            }, Alarm.AlarmMode.Oneshot);
        }
Esempio n. 7
0
        private IEnumerator LookRoutine(Player player)
        {
            Level        level        = SceneAs <Level>();
            SandwichLava sandwichLava = Scene.Entities.FindFirst <SandwichLava>();

            if (sandwichLava != null)
            {
                sandwichLava.Waiting = true;
            }

            if (player.Holding != null)
            {
                player.Drop();
            }

            player.StateMachine.State = Player.StDummy;
            yield return(player.DummyWalkToExact((int)X, walkBackwards: false, 1f, cancelOnFall: true));

            if (Math.Abs(X - player.X) > 4f || player.Dead || !player.OnGround())
            {
                if (!player.Dead)
                {
                    player.StateMachine.State = Player.StNormal;
                }
                yield break;
            }

            Audio.Play("event:/game/general/lookout_use", Position);

            if (player.Facing == Facings.Right)
            {
                sprite.Play(animPrefix + "lookRight");
            }
            else
            {
                sprite.Play(animPrefix + "lookLeft");
            }

            player.Sprite.Visible = player.Hair.Visible = false;
            yield return(0.2f);

            nodePercent = 0f;
            node        = 0;

            Audio.Play("event:/ui/game/lookout_on");

            float accel    = 800f;
            float maxSpeed = 240f;

            Vector2 cam            = level.Camera.Position;
            Vector2 speed          = Vector2.Zero;
            Vector2 lastDir        = Vector2.Zero;
            Vector2 camStart       = level.Camera.Position;
            Vector2 camStartCenter = camStart + new Vector2(160f, 90f);

            while (!Input.MenuCancel.Pressed && !Input.MenuConfirm.Pressed && !Input.Dash.Pressed && !Input.Jump.Pressed && interacting)
            {
                Vector2 value = Input.Aim.Value;
                if (onlyY)
                {
                    value.X = 0f;
                }

                if (Math.Sign(value.X) != Math.Sign(lastDir.X) || Math.Sign(value.Y) != Math.Sign(lastDir.Y))
                {
                    Audio.Play("event:/game/general/lookout_move", Position);
                }

                lastDir = value;

                if (sprite.CurrentAnimationID != "lookLeft" && sprite.CurrentAnimationID != "lookRight")
                {
                    if (value.X == 0f)
                    {
                        if (value.Y == 0f)
                        {
                            sprite.Play(animPrefix + "looking");
                        }
                        else if (value.Y > 0f)
                        {
                            sprite.Play(animPrefix + "lookingDown");
                        }
                        else
                        {
                            sprite.Play(animPrefix + "lookingUp");
                        }
                    }
                    else if (value.X > 0f)
                    {
                        if (value.Y == 0f)
                        {
                            sprite.Play(animPrefix + "lookingRight");
                        }
                        else if (value.Y > 0f)
                        {
                            sprite.Play(animPrefix + "lookingDownRight");
                        }
                        else
                        {
                            sprite.Play(animPrefix + "lookingUpRight");
                        }
                    }
                    else if (value.X < 0f)
                    {
                        if (value.Y == 0f)
                        {
                            sprite.Play(animPrefix + "lookingLeft");
                        }
                        else if (value.Y > 0f)
                        {
                            sprite.Play(animPrefix + "lookingDownLeft");
                        }
                        else
                        {
                            sprite.Play(animPrefix + "lookingUpLeft");
                        }
                    }
                }

                if (nodes == null)
                {
                    speed += accel * value * Engine.DeltaTime;
                    if (value.X == 0f)
                    {
                        speed.X = Calc.Approach(speed.X, 0f, accel * 2f * Engine.DeltaTime);
                    }
                    if (value.Y == 0f)
                    {
                        speed.Y = Calc.Approach(speed.Y, 0f, accel * 2f * Engine.DeltaTime);
                    }
                    if (speed.Length() > maxSpeed)
                    {
                        speed = speed.SafeNormalize(maxSpeed);
                    }

                    List <Entity> lookoutBlockers = Scene.Tracker.GetEntities <LookoutBlocker>();

                    Vector2 vector = cam;

                    cam.X += speed.X * Engine.DeltaTime;
                    if (cam.X < level.Bounds.Left || cam.X + 320f > level.Bounds.Right)
                    {
                        speed.X = 0f;
                    }
                    cam.X = Calc.Clamp(cam.X, level.Bounds.Left, level.Bounds.Right - 320);

                    foreach (Entity item in lookoutBlockers)
                    {
                        if (cam.X + 320f > item.Left && cam.Y + 180f > item.Top && cam.X < item.Right && cam.Y < item.Bottom)
                        {
                            cam.X   = vector.X;
                            speed.X = 0f;
                        }
                    }

                    cam.Y += speed.Y * Engine.DeltaTime;
                    if (cam.Y < level.Bounds.Top || cam.Y + 180f > level.Bounds.Bottom)
                    {
                        speed.Y = 0f;
                    }
                    cam.Y = Calc.Clamp(cam.Y, level.Bounds.Top, level.Bounds.Bottom - 180);

                    foreach (Entity item2 in lookoutBlockers)
                    {
                        if (cam.X + 320f > item2.Left && cam.Y + 180f > item2.Top && cam.X < item2.Right && cam.Y < item2.Bottom)
                        {
                            cam.Y   = vector.Y;
                            speed.Y = 0f;
                        }
                    }

                    level.Camera.Position = cam;
                }
                else
                {
                    Vector2 from = (node <= 0) ? camStartCenter : nodes[node - 1];
                    Vector2 to   = nodes[node];

                    float d = (from - to).Length();

                    if (nodePercent < 0.25f && node > 0)
                    {
                        Vector2 begin = Vector2.Lerp((node <= 1) ? camStartCenter : nodes[node - 2], from, 0.75f);
                        Vector2 end   = Vector2.Lerp(from, to, 0.25f);

                        SimpleCurve simpleCurve = new SimpleCurve(begin, end, from);
                        level.Camera.Position = simpleCurve.GetPoint(0.5f + nodePercent / 0.25f * 0.5f);
                    }
                    else if (nodePercent > 0.75f && node < nodes.Count - 1)
                    {
                        Vector2 nodeVec = nodes[node + 1];
                        Vector2 begin   = Vector2.Lerp(from, to, 0.75f);
                        Vector2 end     = Vector2.Lerp(to, nodeVec, 0.25f);

                        SimpleCurve simpleCurve = new SimpleCurve(begin, end, to);
                        level.Camera.Position = simpleCurve.GetPoint((nodePercent - 0.75f) / 0.25f * 0.5f);
                    }
                    else
                    {
                        level.Camera.Position = Vector2.Lerp(from, to, nodePercent);
                    }

                    level.Camera.Position += new Vector2(-160f, -90f);

                    nodePercent -= value.Y * (maxSpeed / d) * Engine.DeltaTime;
                    if (nodePercent < 0f)
                    {
                        if (node > 0)
                        {
                            node--;
                            nodePercent = 1f;
                        }
                        else
                        {
                            nodePercent = 0f;
                        }
                    }
                    else if (nodePercent > 1f)
                    {
                        if (node < nodes.Count - 1)
                        {
                            node++;
                            nodePercent = 0f;
                        }
                        else
                        {
                            nodePercent = 1f;
                            if (summit)
                            {
                                break;
                            }
                        }
                    }

                    float num2 = 0f;
                    float num3 = 0f;

                    for (int i = 0; i < nodes.Count; i++)
                    {
                        float num4 = (((i == 0) ? camStartCenter : nodes[i - 1]) - nodes[i]).Length();
                        num3 += num4;

                        if (i < node)
                        {
                            num2 += num4;
                        }
                        else if (i == node)
                        {
                            num2 += num4 * nodePercent;
                        }
                    }
                }

                yield return(null);
            }

            player.Sprite.Visible = (player.Hair.Visible = true);
            sprite.Play(animPrefix + "idle");
            Audio.Play("event:/ui/game/lookout_off");

            bool atSummitTop = summit && node >= nodes.Count - 1 && nodePercent >= 0.95f;

            if (atSummitTop)
            {
                yield return(0.5f);

                float duration = 3f;
                float approach = 0f;

                Coroutine component = new Coroutine(level.ZoomTo(new Vector2(160f, 90f), 2f, duration));
                Add(component);

                while (!Input.MenuCancel.Pressed && !Input.MenuConfirm.Pressed && !Input.Dash.Pressed && !Input.Jump.Pressed && interacting)
                {
                    approach = Calc.Approach(approach, 1f, Engine.DeltaTime / duration);
                    Audio.SetMusicParam("escape", approach);
                    yield return(null);
                }
            }

            if ((camStart - level.Camera.Position).Length() > 600f)
            {
                Vector2 was       = level.Camera.Position;
                Vector2 direction = (was - camStart).SafeNormalize();

                float approach = atSummitTop ? 1f : 0.5f;
                new FadeWipe(Scene, wipeIn: false).Duration = approach;
                for (float t = 0f; t < 1f; t += Engine.DeltaTime / approach)
                {
                    level.Camera.Position = was - direction * MathHelper.Lerp(0f, 64f, Ease.CubeIn(t));
                    yield return(null);
                }
                level.Camera.Position = camStart + direction * 32f;
                new FadeWipe(Scene, wipeIn: true);
            }

            Audio.SetMusicParam("escape", 0f);

            level.ZoomSnap(Vector2.Zero, 1f);
            interacting = false;
            yield return(.1f);

            player.StateMachine.State = Player.StNormal;
        }