Exemplo n.º 1
0
 public MyObject(Canvas space, double x, double y, MyObject parent)
 {
     this.parent = parent;
     MyObject.space = space;
     this.heading = random.Next(0, 360);
     this.id = idCounter++;
     point = new Point(x, y);
     s.SetValue(Canvas.LeftProperty, this.point.X);
     s.SetValue(Canvas.TopProperty, this.point.Y);
     MyObject.space.Children.Add(s);
     MyObject.space.Children.Add(line);
     go = new Action(Go);
     Move();
 }
Exemplo n.º 2
0
 private void Go()
 {
     double angle = heading * (Math.PI / 180);
     point.X = point.X + Math.Cos(angle) * speed;
     point.Y = point.Y - Math.Sin(angle) * speed;
     Bounce();
     nearest = GetNearest();
     if (nearest != null)
     {
         line.X1 = this.point.X+5;
         line.Y1 = this.point.Y+5;
         line.X2 = nearest.point.X+5;
         line.Y2 = nearest.point.Y+5;
     }
     s.SetValue(Canvas.LeftProperty, this.point.X);
     s.SetValue(Canvas.TopProperty, this.point.Y);
     Move();
 }
Exemplo n.º 3
0
 private double DistanceTo(MyObject other)
 {
     return Math.Sqrt(Square(this.point.X - other.point.X) + Square(this.point.Y - other.point.Y));
 }
Exemplo n.º 4
0
 private void canvas1_MouseDown(object sender, MouseButtonEventArgs e)
 {
     Point p = Mouse.GetPosition(canvas1);
     MyObject myObj = new MyObject(canvas1, p.X, p.Y, top);
     top = myObj;
 }