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)
            {
            }
            if (target != null)
            {

                FaceTarget();

                if (!IsInRange(target.Center) || target.IsDead)
                {
                    //enemy.IsDead = true;
                    target = null;
                    bulletTimer = 0;

                }

            }
        }
示例#3
0
 private void AddEnemy()
 {
     if (waveNumber >= 2)
     {
         FastEnemy fenemy = new FastEnemy(enemyTexture, level.Waypoints.Peek(), 10, 3, 1.5f);
         fenemy.SetWaypoints(level.Waypoints);
         enemies.Add(fenemy);
         spawnTimer = 0;
         enemiesSpawned++;
     }
     else
     {
         Enemy enemy = new Enemy(enemyTexture, level.Waypoints.Peek(), 100, 3, 0.5f);
         enemy.SetWaypoints(level.Waypoints);
         enemies.Add(enemy);
         spawnTimer = 0;
         enemiesSpawned++;
     }
 }