public void MoveByVector(Point v, double speed) // 벡터 v의 방향으로 speed의 속도로 등속운동한다. { double N = Method2D.Distance(new Point(0, 0), v); int Dis_X = (int)(v.X * speed / N); int Dis_Y = (int)(v.Y * speed / N); Pos = new Point(Bound.X + Dis_X, Bound.Y + Dis_Y); }
public void MoveByVector(Point p, double speed) { double N = Method2D.Distance(new Point(0, 0), p); int Dis_X = (int)(p.X * speed / N); int Dis_Y = (int)(p.Y * speed / N); Pos = new Point(Pos.X + Dis_X, Pos.Y + Dis_Y); Align(); }
public void MoveTo(int x, int y, double speed) // (x,y)를 향해 등속운동. { double N = Method2D.Distance(new Point(x, y), Pos); //두 물체 사이의 거리 if (N < speed) //거리가 스피드보다 가까우면 도착. { Pos = new Point(x, y); return; } Vector2 v = new Vector2(x - Pos.X, y - Pos.Y); v.Normalize(); v = new Vector2((float)speed * v.X, (float)speed * v.Y); Pos = new Point(Bound.X + (int)(v.X), Bound.Y + (int)(v.Y)); }