Exemplo n.º 1
0
        public void findEnemy(List<Enemy> enemies)
        {
            targetEnemy = null;

            foreach (Enemy enemy in enemies)
            {
                //if the tower and enemy are within fire radius, then set enemy as the target
                if (Vector2.Distance(getCenter, enemy.getCenter) <= fireRadius)
                {
                    targetEnemy = enemy;
                }
            }
        }
Exemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            projectileTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (targetEnemy != null)
            {
                //turn towards enemy if within distance
                lookAtEnemy();

                //if not within distance, target is null, stop turning
                if (!withinRadius(targetEnemy.getCenter) || targetEnemy.enemyDead)
                {
                    targetEnemy = null;
                    projectileTimer = 0;
                }
            }
        }
Exemplo n.º 3
0
        //add an enemy to the list
        private void AddEnemy()
        {
            enemy = new Enemy(spriteAnimation, enemyPathing.Pathing.Peek(), enemyHealth, enemyMoney, Enemy.getEnemySpeed);
            enemy.CopyPathing(enemyPathing.Pathing);
            enemies.Add(enemy);
            spawnTimer = 0;

            enemyCount++;
        }