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; } } }
private void AddEnemy() { Enemy enemy = new Enemy(enemyTexture,level.Waypoints.Peek(),50 + waveNumber * 20,(waveNumber+1)*2,(waveNumber+1)*0.5f); enemy.SetWaypoints(level.Waypoints); enemies.Add(enemy); spawnTimer = 0; enemiesSpawned++; }
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; } } }