void MoveBaloon(object sender, EventArgs e) { //Clear old positions of baloons canvas.Children.Clear(); //Change coordinates of all existing baloons for (int i = BaloonsList.Count - 1; i >= 0; i--) { //Check if baloon is not crossing the top if (Canvas.GetBottom(BaloonsList[i]) <= canvas.Height) { Canvas.SetBottom(BaloonsList[i], Canvas.GetBottom(BaloonsList[i]) + 1); canvas.Children.Add(BaloonsList[i]); } else { //Detete baloon if its crossing the top BaloonsList.Remove(BaloonsList[i]); baloonsMissed++; } } }
public void DestroyBaloon(Ellipse baloon) { baloon.Fill = new SolidColorBrush(Color.FromRgb(255, 0, 0)); baloon.Opacity = .8; var doubleAnimationWidth = new DoubleAnimation(); doubleAnimationWidth.From = baloon.Width; doubleAnimationWidth.To = baloon.Width + 20; doubleAnimationWidth.Duration = new Duration(TimeSpan.FromMilliseconds(5000)); var doubleAnimationHeight = new DoubleAnimation(); doubleAnimationHeight.From = baloon.Height; doubleAnimationHeight.To = baloon.Height + 20; doubleAnimationHeight.Duration = new Duration(TimeSpan.FromMilliseconds(5000)); baloon.BeginAnimation(Ellipse.WidthProperty, doubleAnimationWidth); baloon.BeginAnimation(Ellipse.HeightProperty, doubleAnimationHeight); //Count hitted baloon baloonsHitted++; //Remove baloon from baloons list BaloonsList.Remove(baloon); #region storyboard //#region storyboard //baloon.Fill = new SolidColorBrush(Color.FromRgb(255, 0, 0)); //var storyboard = new Storyboard(); //var doubleAnimation = new DoubleAnimation(); //doubleAnimation.From = baloon.Width; //doubleAnimation.To = baloon.Width + 10; //doubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(3000)); //Storyboard.SetTargetName(doubleAnimation, baloon.Name); //Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(baloon.Width)); //Storyboard WidthStoryboard = new Storyboard(); //WidthStoryboard.Children.Add(doubleAnimation); //WidthStoryboard.Begin(baloon); #endregion #region storyboard 2 //DoubleAnimation widthAnimation = new DoubleAnimation //{ // From = 0, // To = 10, // Duration = TimeSpan.FromSeconds(5) //}; //DoubleAnimation heightAnimation = new DoubleAnimation //{ // From = 0, // To = 10, // Duration = TimeSpan.FromSeconds(5) //}; //Storyboard.SetTargetProperty(widthAnimation, new PropertyPath(Ellipse.WidthProperty)); //Storyboard.SetTarget(widthAnimation, baloon); //Storyboard.SetTargetProperty(heightAnimation, new PropertyPath(Ellipse.HeightProperty)); //Storyboard.SetTarget(heightAnimation, baloon); //Storyboard s = new Storyboard(); //s.Children.Add(widthAnimation); //s.Children.Add(heightAnimation); //s.Begin(); #endregion #region event //this._dispatcherTimer.Tick += delegate (object sender, EventArgs e) //{ // BaloonExplosion(baloon); //}; #endregion }