示例#1
0
        private void ScreenFlash_Loaded(object sender, RoutedEventArgs e)
        {
            var grid = Parent as Panel;

            while (grid is not Grid)
            {
                grid = (Panel)grid.Parent;
            }

            var rect = new Rectangle();

            rect.Fill             = new SolidColorBrush(Colors.White);
            rect.Opacity          = strength;
            rect.IsHitTestVisible = false;
            Panel.SetZIndex(rect, 1);

            grid.Children.Add(rect);

            Add(Lerp.Time(strength, 0, Duration, t => rect.Opacity = t).Then(() =>
            {
                grid.Children.Remove(rect);
                OnCompleted();
                Destroy();
            }));
        }
示例#2
0
        public UserControl Overlay(UserControl screen)
        {
            screen.Opacity = 0;
            Add(Lerp.Time(0, 1, TRANSITION_DURATION, t => screen.Opacity = t));
            Add(screen);

            return(screen);
        }
示例#3
0
        public Trail(Vector from, Vector to, double speed, Color color1, Color color2)
        {
            var trailVector = (to - from).Normalized() * TRAIL_SIZE;

            color1.A = 0;
            var brush = new LinearGradientBrush(color1, color2, from.ToPoint(), to.ToPoint());

            brush.MappingMode = BrushMappingMode.Absolute;

            var line = new Line();

            line.Stroke             = brush;
            line.StrokeThickness    = 2;
            line.StrokeStartLineCap = PenLineCap.Round;
            line.StrokeEndLineCap   = PenLineCap.Round;

            line.X1 = from.X;
            line.Y1 = from.Y;
            line.X2 = from.X;
            line.Y2 = from.Y;

            position = Lerp.Speed(from, to, speed, p =>
            {
                line.X2 = p.X;
                line.Y2 = p.Y;
                Moving?.Invoke(p);
            });

            var brushPosition = Lerp.Speed(from, to + trailVector, speed, p =>
            {
                brush.StartPoint = (p - trailVector).ToPoint();
                brush.EndPoint   = p;
            });

            position.Completed += () =>
            {
                // Destination reached
                Completed?.Invoke();
            };

            brushPosition.Completed += () =>
            {
                // Trail faded completely
                Faded?.Invoke();
                this.Destroy();
            };

            Add(position);
            Add(brushPosition);
            Add(line);
        }
示例#4
0
        private void ScreenShake_Loaded(object sender, RoutedEventArgs e)
        {
            var parent = Parent as Panel;

            Add(Lerp.Time(strength, 0, duration, t =>
            {
                Matrix matrix = parent.RenderTransform.Value;
                matrix.TranslatePrepend(-shakeOffset.X, -shakeOffset.Y);
                shakeOffset = new Vector(Random(-1, 1), Random(-1, 1)) * (double)t;
                matrix.TranslatePrepend(shakeOffset.X, shakeOffset.Y);
                parent.RenderTransform = new MatrixTransform(matrix);
            }).Then(() =>
            {
                OnCompleted();
                Destroy();
            }));
        }
示例#5
0
        public UserControl Switch(UserControl screen)
        {
            var lastScreen = CurrentScreen;

            CurrentScreen  = screen;
            screen.Opacity = 0;

            var animation =
                Lerp.Time(0, 1, TRANSITION_DURATION, t => screen.Opacity     = t) *
                Lerp.Time(1, 0, TRANSITION_DURATION, t => lastScreen.Opacity = t) +
                (() => Remove(lastScreen));

            Add(screen);
            Add(animation);

            InvalidateMeasure();

            return(screen);
        }
示例#6
0
        public event Action <Vector, double> Payload; //is passed position and radius

        public Explosion(Vector position, double radius, double duration)
        {
            circle      = new Ellipse();
            circle.Fill = new SolidColorBrush(Colors.White);

            Position = position;

            var animation =
                // Expand
                Lerp.Time(0, radius, duration, r =>
            {
                Radius        = r;
                circle.Width  = r * 2;
                circle.Height = r * 2;
                Canvas.SetLeft(circle, position.X - r + Random(-1, 1) * SHAKE_FACTOR);
                Canvas.SetTop(circle, position.Y - r + Random(-1, 1) * SHAKE_FACTOR);
                Exploding?.Invoke(Position, Radius);
            }, Lerp.CubeRoot)

                // Contract
                + Lerp.Time(radius, 0, duration, r =>
            {
                Radius        = r;
                circle.Width  = r * 2;
                circle.Height = r * 2;
                Canvas.SetLeft(circle, position.X - r + Random(-1, 1) * SHAKE_FACTOR);
                Canvas.SetTop(circle, position.Y - r + Random(-1, 1) * SHAKE_FACTOR);
                Exploding?.Invoke(Position, Radius);
            })

                // Fade
                * Lerp.Time(1, 0, duration + FADE_DURATION, o => circle.Opacity = o)

                // Destroy
                + (() => this.Destroy());

            Add(animation);
            Add(circle);
            AddToParent(new ScreenFlash(0.1, 0.5));
        }
示例#7
0
 public void CloseOverlay(UserControl screen)
 {
     Add(Lerp.Time(1, 0, TRANSITION_DURATION, t => screen.Opacity = t).Then(() => Remove(screen)));
 }