コード例 #1
0
        public Missile(Vector2 location, Point to, float speed, bool friendly, Color color, bool branched)
        {
            this.position = location;
            this.to       = to;
            this.speed    = speed;
            this.trail    = null;
            this.color    = color;
            this.friendly = friendly;
            this.branched = branched;

            if (friendly)
            {
                this.crosshair = new TargetCrosshair(new Vector2(to.X, to.Y));
            }
            else
            {
                this.crosshair = new TargetCrosshair(new Vector2(-1000, -1000));
            }

            double direction = Math.Atan2(to.X - location.X, to.Y - location.Y);

            speedVector = new Vector2((float)Math.Sin(direction) * speed, (float)Math.Cos(direction) * speed);
        }
コード例 #2
0
        private void EnemyMissile_Loaded(object sender, RoutedEventArgs e)
        {
            var targets = from item in ((Canvas)Parent).Children.OfType <ITargetable>()
                          where item.IsDestroyed == false
                          select item;
            var target = targets.Random();

            this.Target      = target;
            trail            = new Trail(From, Target.TargetPosition, Speed, Colors.Orange, Colors.OrangeRed);
            trail.Moving    += pos => Position = pos;
            trail.Completed += TargetReached;

            var missile = new Image();

            missile.Source = (ImageSource)FindResource("Missile");

            var matrix = new Matrix();

            matrix.RotateAt(180 - From.AngleTo(Target.TargetPosition) * 180.0 / Math.PI, missile.Source.Width / 2, 0);
            matrix.Translate(From.X - missile.Source.Width / 2, From.Y);
            matrix.TranslatePrepend(0, -missile.Source.Height / 2);
            missile.RenderTransform = new MatrixTransform(matrix);

            trail.Moving += pos =>
            {
                var matrix = new Matrix();
                matrix.RotateAt(180 - From.AngleTo(Target.TargetPosition) * 180.0 / Math.PI, missile.Source.Width / 2, 0);
                matrix.Translate(pos.X - missile.Source.Width / 2, pos.Y);
                matrix.TranslatePrepend(0, -missile.Source.Height / 2);
                missile.RenderTransform = new MatrixTransform(matrix);
            };
            Canvas.SetZIndex(trail, -1);

            Add(missile);
            AddToParent(trail);
        }
コード例 #3
0
 public Trail(Vector2 position, Trail next)
 {
     this.position = position;
     this.next     = next;
 }