void t_Tick(object sender, EventArgs e) { if (Ziel != null) { bool bewegt = true; float Speed = 10; Single hSpeed, vSpeed; hSpeed = Ziel.Location.X - this.Location.X; vSpeed = Ziel.Location.Y - this.Location.Y; Single max = Math.Max( Math.Abs(hSpeed), Math.Abs(vSpeed)); hSpeed /= max; vSpeed /= max; hSpeed *= Speed; vSpeed *= Speed; this.Left += (int)hSpeed; this.Top += (int)vSpeed; Rectangle meinRechteck = Rectangle.FromLTRB( this.Left, this.Top, this.Right, this.Bottom); Rectangle zielRechteck = Rectangle.FromLTRB( Ziel.Left, Ziel.Top, Ziel.Right, Ziel.Bottom); if (meinRechteck.IntersectsWith(zielRechteck)) { bewegt = false; this.Left = SchiessenderTurm.Left; this.Top = SchiessenderTurm.Top; } if (!bewegt) { Left = SchiessenderTurm.Left; Top = SchiessenderTurm.Top; Ziel.BehandleTreffer(); Ziel = FindeNaechstenGegnerZuTurm(SchiessenderTurm); } } }
void zielFinder_Tick(object sender, EventArgs e) { if (Ziel == null) Ziel = FindeNaechstenGegnerZuTurm(SchiessenderTurm); }