public virtual void TargetClosestEnemy(List<Enemy> enemies) { this.target = null; float smallest = radius; foreach (Enemy enemy in enemies) { if (Vector2.Distance(base.center, enemy.Center) < smallest) { smallest = Vector2.Distance(base.center, enemy.Center); this.target = enemy; } } }
public override void Update(GameTime gametime) { base.Update(gametime); this.bulletTime += (float)gametime.ElapsedGameTime.TotalSeconds; if (this.target != null) { this.FaceTarget(); if (!this.CanReach(this.target.Center) || target.isDead) { this.target = null; this.bulletTime = 0; } } }