/** * Notifier für das Fallen einer Figur */ public void NotifyFigureFallen(Util.Point[] previousPoints, Util.Point[] points, Color c) { if (FigureFallenEvent != null) { FigureFallenEventArgs ffea = new FigureFallenEventArgs(previousPoints, points, c); FigureFallenEvent(this, ffea); } }
/** * Animationen für das Fallen der Figur * * Wenn die figur unten ankommt, blinkt sie durch opacity. * Wenn die figur durch fallcompeteley gefallen ist, dann wird ein Rechteck von der letzten Position bis unten erstellt * dieses Rechteck verschwindet durch einen lin.gradienten mit transparenter Farbe. */ public void OnFigureFallen(object sender, FigureFallenEventArgs ffea) { Dispatcher.BeginInvoke(delegate { if (iv.rootContainer.Child == this) { hardFall = false; Util.Point[] points = ffea.figurePoints; List<Rectangle> rectangles = getBoardRectangles(points); Storyboard sb = new Storyboard(); sb.Duration = TimeSpan.FromMilliseconds(400); foreach (Rectangle rectangle in rectangles) { Duration duration = TimeSpan.FromMilliseconds(200); DoubleAnimation myDoubleAnimation = new DoubleAnimation(); myDoubleAnimation.Duration = duration; myDoubleAnimation.AutoReverse = true; Storyboard.SetTarget(myDoubleAnimation, rectangle); Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath("Opacity")); myDoubleAnimation.To = 0.5; myDoubleAnimation.From = 1; sb.Children.Add(myDoubleAnimation); } if (!ffea.PointsAreEqual()) { sb.Duration = TimeSpan.FromMilliseconds(3000); hardFall = true; int maxY = getMax(points, false); int minY = getMin(ffea.previousFigurePoints, false); int minX = getMin(points, true); int maxX = getMax(points, true); Rectangle upperLeftRect = getRectangleAt(minX, minY); Rectangle bottomRightRect = getRectangleAt(maxX, maxY); Rectangle bottomLeftRect = getRectangleAt(minX, maxY); Rectangle upperRightRect = getRectangleAt(maxX, minY); System.Windows.Point upperLeftPoint = upperLeftRect.TransformToVisual(this.LayoutRoot).Transform(new System.Windows.Point(0, 0)); System.Windows.Point bottomRightPoint = bottomRightRect.TransformToVisual(this.LayoutRoot).Transform(new System.Windows.Point(0, 0)); System.Windows.Point bottomLeftPoint = bottomLeftRect.TransformToVisual(this.LayoutRoot).Transform(new System.Windows.Point(0, 0)); System.Windows.Point upperRightPoint = upperRightRect.TransformToVisual(this.LayoutRoot).Transform(new System.Windows.Point(0, 0)); double width = Math.Sqrt(Math.Pow(bottomRightPoint.X - bottomLeftPoint.X, 2) + Math.Pow(bottomRightPoint.Y - bottomLeftPoint.Y, 2)) + upperLeftRect.ActualWidth; double height = Math.Sqrt(Math.Pow(bottomRightPoint.X - upperRightPoint.X, 2) + Math.Pow(bottomRightPoint.Y - upperRightPoint.Y, 2)) + bottomLeftRect.ActualHeight; Rectangle effectRectangle = new Rectangle(); effectRectangle.Width = width; effectRectangle.Height = height; CompositeTransform ct = (CompositeTransform)boardBorder.RenderTransform; CompositeTransform ct2 = new CompositeTransform(); ct2.Rotation = ct.Rotation; effectRectangle.RenderTransform = ct2; LinearGradientBrush lgb = new LinearGradientBrush(); RotateTransform rt = new RotateTransform(); rt.Angle = 0; lgb.Transform = rt; GradientStop gs1 = new GradientStop(); gs1.Color = Colors.Transparent; gs1.Offset = 0.0; GradientStop gs2 = new GradientStop(); gs2.Color = Color.FromArgb(100, ffea.color.R, ffea.color.G, ffea.color.B); gs2.Offset = 0.0; lgb.GradientStops.Add(gs1); lgb.GradientStops.Add(gs2); effectRectangle.Fill = lgb; canvas.Children.Add(effectRectangle); Canvas.SetLeft(effectRectangle, upperLeftPoint.X + Canvas.GetLeft(LayoutRoot)); Canvas.SetTop(effectRectangle, upperLeftPoint.Y + Canvas.GetTop(LayoutRoot)); Duration duration = TimeSpan.FromMilliseconds(3000); DoubleAnimation myDoubleAnimation = new DoubleAnimation(); myDoubleAnimation.Duration = duration; Storyboard.SetTarget(myDoubleAnimation, gs2); Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath("Offset")); myDoubleAnimation.To = 10.0; sb.Children.Add(myDoubleAnimation); sb.Completed += new EventHandler((a, b) => { canvas.Children.Remove(effectRectangle); }); } if (!LayoutRoot.Resources.Contains("unique_id")) { LayoutRoot.Resources.Add("unique_id", sb); } sb.Begin(); } }); }