Beispiel #1
0
        public ContinuityStoryboard WalkWithJumpAnimate(int Count)
        {
            ContinuityStoryboard csb = new ContinuityStoryboard();
            var begin = (Storyboard)Resources["ReadyWalkWithJump"];

            ((DoubleAnimationUsingKeyFrames)begin.Children[0]).KeyFrames[0].Value = RotateTransform.Angle;
            ((DoubleAnimationUsingKeyFrames)begin.Children[1]).KeyFrames[0].Value = TranslateTransform.X;
            ((DoubleAnimationUsingKeyFrames)begin.Children[2]).KeyFrames[0].Value = TranslateTransform.Y;
            csb.Add(begin);

            var sb = (Storyboard)Resources["WalkWithJump"];

            sb.RepeatBehavior = new RepeatBehavior(Count);
            csb.Add(sb);

            var end = (Storyboard)Resources["FinishWalkWithJump"];

            csb.Add(end);
            csb.CurrentStoryboardChanging += (sender, e) =>
            {
                if (e.Storyboard == end)
                {
                    ((DoubleAnimationUsingKeyFrames)end.Children[0]).KeyFrames[0].Value = RotateTransform.Angle;
                    ((DoubleAnimationUsingKeyFrames)end.Children[1]).KeyFrames[0].Value = TranslateTransform.X;
                    ((DoubleAnimationUsingKeyFrames)end.Children[2]).KeyFrames[0].Value = TranslateTransform.Y;
                }
            };

            return(csb);
        }
Beispiel #2
0
        private void AnimPlayB_Click(object sender, RoutedEventArgs e)
        {
            ContinuityStoryboard csb = null;

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

            csb?.BeginAnimation();
        }
        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();
        }