public void GetClosestEnemy(List<Enemy> enemies) { target = null; float smallestRange = radius; foreach (Enemy enemy in enemies) { if (Vector2.Distance(center, enemy.Center) < smallestRange) { smallestRange = Vector2.Distance(center, enemy.Center); target = enemy; } } }
public override void Update(GameTime gameTime) { base.Update(gameTime); bulletTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (target != null) { FaceTarget(); if (!IsInRange(target.Center) || target.IsDead) { target = null; bulletTimer = 0; foreach (Bullet bullet in bulletList) { bullet.Kill(); } } } }