Exemplo n.º 1
0
        private void HandleEnemies()
        {
            //patrol enemies
            foreach (Enemy enemy in _map.GetEnemies())
            {
                enemy.Patrol(_game, _map, _player);
            }

            //collision with shots fired from player
            List <Enemy> TempEnemies = new List <Enemy>(_map.GetEnemies());

            foreach (Enemy enemy in TempEnemies)
            {
                if (enemy.IsCollidingWithProjectile(_player.GetShots(), enemy.GetPositionInCanvas(), out Projectile projectile))
                {
                    //hit the enemy
                    enemy.Hit(enemy.shotDmg);

                    //delete the shot
                    projectile.Remove(_player.GetShots());
                    hitFx.Play();
                    //check if enemy died
                    if (!enemy.IsAlive)
                    {
                        //player killed enemy
                        _player.KillEnemy(_map);
                        enemyDeath.Play();
                        //map lost enemy
                        _map.RemoveEnemy(enemy);
                    }
                    //update visual representation of score
                    InitializeScore();
                }
            }

            //if there is a boss
            if (_map.GetBoss() != null)
            {
                //collision with player shots
                if (_map.GetBoss().IsCollidingWithProjectile(_player.GetShots(), _map.GetBoss().GetPositionInCanvas(), out Projectile projectile))
                {
                    //hit the boss
                    _map.GetBoss().Hit(Player.ShotDmg);

                    UpdateBossHealthVisual();

                    //delete the shot
                    projectile.Remove(_player.GetShots());

                    if (!_map.GetBoss().IsAlive)
                    {
                        _player.KillBoss();

                        _map.CompleteLvl();
                    }
                    //update visual representation of score
                    InitializeScore();
                }

                //logic
                if (_map.GetBoss() != null)
                {
                    _map.GetBoss().BossLogic(_game, _player, _map);
                }
                InitializeHealthBar();
            }
        }