예제 #1
0
        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;
                }
            }
        }
예제 #2
0
 private void AddEnemy()
 {
     // Enemy enemy = new Enemy(enemyTexture, level.Waypoints.Peek(), 50 + waveNumber * 20, (waveNumber + 1) * 2, (waveNumber + 1) * 0.5f);
     int randomEnemyIndex = SelectEnemy(enemyTexture.Count());
     Enemy enemy = new Enemy(enemyTexture[randomEnemyIndex], level.Waypoints.Peek(),/*enemyHealthList [randomEnemyIndex ]*/ 50 + waveNumber * 20, (waveNumber + 1) * 2, (waveNumber + 1) * 0.5f);
     enemy.SetWaypoints(level.Waypoints);
     enemies.Add(enemy);
     spawnTimer = 0;
     enemiesSpawned++;
 }
예제 #3
0
        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;
                }
            }
        }
예제 #4
0
 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++;
 }