Пример #1
0
        private void AnimPlayB_Click(object sender, RoutedEventArgs e)
        {
            ContinuityStoryboard csb = null;

            if (WalkWithJumpR.IsChecked ?? false)
            {
                csb = MascotPreview.WalkWithJumpAnimate(TimeSpan.FromSeconds(5));
            }

            csb?.BeginAnimation();
        }
Пример #2
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (Player.IsValueCreated)
            {
                if (Player.Value.IsPlaying)
                {
                    return;
                }
            }

            if (prof.Behavior == MascotBehavior.None)
            {
                return;
            }

            animating = true;
            const double DurationParHandred = 600;
            double       Y = 0;
            double       X = 0;

            if (prof.Behavior == MascotBehavior.Walk)
            {
                Random RDeltaX = new Random(Environment.TickCount);
                Random RDeltaY = new Random(Environment.TickCount + 10);

                Y = RDeltaY.NextDouble() * (SystemParameters.WorkArea.Height - ViewParent.Height);
                X = RDeltaX.NextDouble() * (SystemParameters.WorkArea.Width - ViewParent.Width);
            }
            else if (prof.Behavior == MascotBehavior.Follow)
            {
                const double         regionThresh = 50;
                System.Drawing.Point point        = System.Windows.Forms.Control.MousePosition;

                if (point.X < 0)
                {
                    point.X = 0;
                }
                else if (SystemParameters.WorkArea.Width <= point.X + ViewParent.Width)
                {
                    point.X = (int)(SystemParameters.WorkArea.Width - ViewParent.Width);
                }

                if (point.Y < 0)
                {
                    point.Y = 0;
                }
                else if (SystemParameters.WorkArea.Height <= point.Y + ViewParent.Height)
                {
                    point.Y = (int)(SystemParameters.WorkArea.Height - ViewParent.Height);
                }

                Thickness region = new Thickness(ViewParent.Margin.Left - regionThresh, ViewParent.Margin.Top - regionThresh,
                                                 ViewParent.Margin.Left + ViewParent.Width + regionThresh, ViewParent.Margin.Top + ViewParent.Height + regionThresh);

                if (IsInsideOfRegion(point.X, point.Y, region))
                {
                    return;
                }

                X = point.X;
                Y = point.Y;
            }

            double   dX = ViewParent.Margin.Left - X, dY = ViewParent.Margin.Top - Y;
            double   length   = Math.Sqrt((dX * dX) + (dY * dY));
            double   duration = length / 100 * DurationParHandred;
            TimeSpan tdur     = TimeSpan.FromMilliseconds(duration);

            ContinuityStoryboard csb = MascotV.WalkWithJumpAnimate(tdur);

            csb.CurrentStoryboardChanging += (_, ev) =>
            {
                if (ev.Index == 1)
                {
                    ThicknessAnimation ta = new ThicknessAnimation(ViewParent.Margin, new Thickness(X, Y, 0, 0), new Duration(tdur))
                    {
                        FillBehavior = FillBehavior.Stop
                    };
                    ta.Completed += (_1, _2) =>
                    {
                        ViewParent.Margin = new Thickness(X, Y, 0, 0);
                        animating         = false;
                    };

                    ViewParent.BeginAnimation(MarginProperty, ta);
                }
            };
            csb.Completed += (_, _2) =>
            {
                csb.StopAnimation();
                timer.Start();
            };
            csb.BeginAnimation();
            timer.Stop();
        }