Example #1
0
        public void AutoTurnPage(CornerOrigin fromCorner, int duration)
        {
            if (Status != PageStatus.None)
                return;

            Status = PageStatus.TurnAnimation;

            UIElement source = this as UIElement;

            this.BeginAnimation(BookPage.CornerPointProperty, null);

            Point startPoint = OriginToPoint(this, fromCorner);
            Point endPoint = OriginToOppositePoint(this, fromCorner);

            CornerPoint = startPoint;
            origin = fromCorner;

            BezierSegment bs =
                new BezierSegment(startPoint, new Point(endPoint.X + (startPoint.X - endPoint.X) / 3, 250), endPoint, true);

            PathGeometry path = new PathGeometry();
            PathFigure figure = new PathFigure();
            figure.StartPoint = startPoint;
            figure.Segments.Add(bs);
            figure.IsClosed = false;
            path.Figures.Add(figure);

            PointAnimationUsingPath anim =
                new PointAnimationUsingPath();
            anim.PathGeometry = path;
            anim.Duration = new Duration(TimeSpan.FromMilliseconds(duration));
            anim.AccelerationRatio = 0.6;

            anim.CurrentTimeInvalidated += new EventHandler(anim_CurrentTimeInvalidated);
            anim.Completed += new EventHandler(anim_Completed);
            this.BeginAnimation(BookPage.CornerPointProperty, anim);
        }
Example #2
0
        private void HitBall(int index, Vector velocity, bool isPlayerOne)
        {
            var heldBalls = isPlayerOne ? game.PlayerOneHeldBalls : game.PlayerTwoHeldBalls;
            var ballHolders = isPlayerOne ? _playerOneBallHolders : _playerTwoBallHolders;
            var pushedBall = heldBalls[index];
            // Check if any running animations to avoid conflicts
            if (this.gameActive && runningAnimations.Count == 0 && game.PushBall(pushedBall))
            {
                var ballHolder = ballHolders[index];
                uxMainCanvas.Children.Add(pushedBall);

                // TODO2: Trigger animation for ball and after animation is triggered

                PointAnimationUsingPath ballAnimation = new PointAnimationUsingPath();
                PathGeometry animationPath = new PathGeometry();
                PathFigure pFigure = new PathFigure();
                pFigure.StartPoint = PointCanvas.GetTopLeft(ballHolder);
                //PathFigureCollection pfc = FindResource("RectanglePathFigureCollection") as PathFigureCollection;
                UIElement targetPanel = isPlayerOne ? ((UIElement) seesaw.leftBallPanel) : seesaw.rightBallPanel;
                Point endPoint = new Point(
                    Canvas.GetLeft(seesaw) + Canvas.GetLeft(seesaw.uxBalanceCanvas) + Canvas.GetLeft(targetPanel),
                    Canvas.GetTop(seesaw) + Canvas.GetTop(seesaw.uxBalanceCanvas) + Canvas.GetTop(targetPanel)
                );
                pFigure.Segments.Add(ComputeCurve(pFigure.StartPoint, endPoint, velocity));

                animationPath.Figures.Add(pFigure);
                // Freeze the PathGeometry for performance benefits.
                animationPath.Freeze();

                ballAnimation.PathGeometry = animationPath;
                ballAnimation.BeginTime = TimeSpan.FromSeconds(0);
                ballAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.75));
                ballAnimation.AutoReverse = false;

                Storyboard.SetTarget(ballAnimation, pushedBall);
                Storyboard.SetTargetProperty(ballAnimation, new PropertyPath("(TopLeft)"));
                Storyboard ballMove = new Storyboard();
                ballMove.Children.Add(ballAnimation);
                runningAnimations.Add(ballMove);

                ballMove.Completed += delegate
                {
                    selectingBall = false;
                    uxMainCanvas.Children.Remove(pushedBall);
                    runningAnimations.Remove(ballMove);
                    (pushedBall as Bird).IsFlying = false;
                    // Reset ball move animation
                    pushedBall.BeginAnimation(SeesawObject.TopLeftProperty, null);
                    game.AddBallToBalance(pushedBall, isPlayerOne);
                };
                selectingBall = true;
                ballMove.Begin();
                // TODO2: Trigger animation for ball and after animation is triggered
            }
        }
        private void startBrickAnimation()
        {
            PointAnimationUsingPath ballAnimation = new PointAnimationUsingPath();
            PathGeometry animationPath = new PathGeometry();
            PathFigure pFigure = new PathFigure();
            //I don't know how to get its position....
            pFigure.StartPoint = new Point(607, 228);
            Point endPoint = new Point(200,200);
            pFigure.Segments.Add(MainView.ComputeCurve(pFigure.StartPoint, endPoint, new Vector(0,0)));

            animationPath.Figures.Add(pFigure);
            // Freeze the PathGeometry for performance benefits.
            animationPath.Freeze();

            /*
            animationPath.Figures = pfc;*/
            ballAnimation.PathGeometry = animationPath;
            ballAnimation.BeginTime = TimeSpan.FromSeconds(0);
            ballAnimation.Duration = new Duration(TimeSpan.FromSeconds(2));
            ballAnimation.AutoReverse = false;

            Storyboard.SetTarget(ballAnimation, bird2);
            Storyboard.SetTargetProperty(ballAnimation, new PropertyPath("(TopLeft)"));
            Storyboard ballMove = new Storyboard();
            ballMove.Children.Add(ballAnimation);

            ballMove.Completed += delegate
            {
                this.SendMessage(new ChangeViewMessage(typeof(MainView)));
            };
            ballMove.Begin();
        }
Example #4
0
        /// <summary>
        /// Funkja przygotowywująca animację na podstawie rozmiaru obiektu canvas
        /// </summary>
        /// <param name="geometry">Aktualny obiekt geometry</param>
        private void PrepareAnimation(EllipseGeometry geometry)
        {
            double space = playField.ActualWidth / baloons;
            j += (int)space + 50;
            if (j > playField.ActualWidth)
            {
                j = Convert.ToInt32(j % playField.ActualWidth);
            }

            geometry.Center = new Point(j, -50);
            up = new PointAnimationUsingPath();
            pBezierSegment = new PolyBezierSegment();
            animationPath = new PathGeometry();
            pFigure = new PathFigure();

            pFigure.StartPoint = new Point(j, -50);
            for (int i = 0; (i < playField.ActualHeight); i += 25)
            {
                int randomSign = random.Next(1);
                if (randomSign == 0)
                {
                    pBezierSegment.Points.Add(new Point(j - random.Next(30), i));
                }
                else if (randomSign == 1)
                {
                    pBezierSegment.Points.Add(new Point(j + random.Next(30), i));
                }
            }
            pBezierSegment.Points.Add(new Point(j, playField.ActualHeight + 50));

            pFigure.Segments.Add(pBezierSegment);
            animationPath.Figures.Add(pFigure);
            up.PathGeometry = animationPath;
            if (timesIndex != times.Count)
            {
                up.BeginTime = TimeSpan.FromSeconds(Convert.ToInt32(times[timesIndex]));
                timesIndex++;
            }

            up.Duration = TimeSpan.FromSeconds(10);
            up.SpeedRatio = 0.5;
            up.RepeatBehavior = RepeatBehavior.Forever;
            animationPath.Freeze();
            geometry.BeginAnimation(EllipseGeometry.CenterProperty, up);
        }