Hallo
Ich versuche gerade eine Art Verfolgung zu schreiben. Also ein Objekt (Shape oder Image z.B) verfolgt ein Anderes. Ich bin zwar schon recht weit, allerdings hab ich das Gefühl ich bin da etwas zu kompliziert ran gegangen und es gibt auch noch ein paar Fehler. (z.B. bleibt er ohne Grund stehen)
Die Verfolgung soll nicht nur über eine Gerade Strecke geschehen. Hier mal mein bescheidener Versuch
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43:
| procedure TForm1.SetNewPosition(Point1:TPoint; Point2:TPoint; k:Integer); VAR x,y,y2,y2tmp,x2: Integer; a,l: Real; begin x := Point1.X - Point2.X; If x < 0 Then x := -x;
y := Point1.Y - Point2.Y; If y < 0 Then y := -y;
l := sqrt( sqr(x) + sqr(y) ); l := l-k;
a := ( arctan(x/y) ); a := RadToDeg(a);
If (Point1.X <> Point2.X) or (Point1.Y <> Point2.Y) Then begin y2 := round(cos(DegToRad(a)) * l); y2tmp := y2;
If (Point1.Y < Point2.Y) Then y2 := round(Point1.Y + (y-y2)); If (Point1.Y > Point2.Y) Then y2 := round(Point1.Y - (y-y2));
x2 := round(tan(DegToRad(a)) * y2tmp); If (Point1.X > Point2.X) Then x2 := round(Point1.X - (x-x2)); If (Point1.X < Point2.X) Then x2 := round(Point1.X + (x-x2));
Shape1.Left := x2; Shape1.Top := y2; end; |
Wäre nett wenn mir einer helfen könnte
Danke schonmal.