/// <summary> /// Updates the enemies and checks for destroyed enemies /// </summary> public static void Update(GameTime gt) { foreach (Enemy Enemy in Enemies) { if (Enemy.IsDestroyed) { WaveManager.WaveEnemiesUsed++; if (Enemy.hitPoints <= 0) // check if it was destroyed by means of towers { GameManager.EnemyWasDestroyed(Enemy.EnemyType); // resource acquisition if (Enemy.EnemyType == "Helicopter") { EffectManager.EffectCall(EffectManager.EffectEnums.Explosion, Enemy.ScreenPos - new Vector2(Art.Helicopter.Width / 2, Art.Helicopter.Height / 2), true); } if (Enemy.EnemyType == "Transport") { for (float i = 0; i < 4; i++) { WaveManager.WaveEnemiesUsed--; SpawnEnemy("Soldier", Enemy.enemyVect - new Vector2(Enemy.Direction.X * -i / 4, Enemy.Direction.Y * -i / 4)); EffectManager.EffectCall(EffectManager.EffectEnums.Explosion, Enemy.ScreenPos - new Vector2(Art.Transport.Width / 2, Art.Transport.Height / 2), true); } } else if (Enemy.EnemyType == "Tank") { for (float i = 0; i < 2; i++) { WaveManager.WaveEnemiesUsed--; SpawnEnemy("Soldier", Enemy.enemyVect - new Vector2(Enemy.Direction.X * -i / 4, Enemy.Direction.Y * -i / 4)); EffectManager.EffectCall(EffectManager.EffectEnums.Explosion, Enemy.ScreenPos - new Vector2(Art.TankBottom.Width / 2, Art.TankBottom.Height / 2), true); } } else if (Enemy.EnemyType == "Jeep") { for (float i = 0; i < 1; i++) { WaveManager.WaveEnemiesUsed--; SpawnEnemy("Soldier", Enemy.enemyVect - new Vector2(Enemy.Direction.X * -i / 4, Enemy.Direction.Y * -i / 4)); EffectManager.EffectCall(EffectManager.EffectEnums.Explosion, Enemy.ScreenPos - new Vector2(Art.JeepBottom.Width / 2, Art.JeepBottom.Height / 2), true); } } else if (Enemy.EnemyType == "Soldier") { EffectManager.EffectCall(EffectManager.EffectEnums.Blood, Enemy.ScreenPos, false); } } DestroyEnemy(Enemy.EnemyID, Enemy.EnemyType); break; } else { Enemy.Update(GameManager.grid.gridStatus, gt); //updates the enemy } } foreach (Projectile proj in TankTurret.EnemyProjectiles) //updates the projectiles of enemy { proj.Update(); } }
/// <summary> /// Updates the enemies and checks for destroyed enemies /// </summary> public static void Update(GameTime gt) { if (WaveManager.WaveNumber > 10) { SpawnSoldierString = "SoldierBlue"; } if (WaveManager.WaveNumber > 20) { SpawnSoldierString = "SoldierRed"; } foreach (Enemy Enemy in Enemies) { if (Enemy.IsDestroyed) { if (Enemy.hitPoints <= 0) // check if it was destroyed by means of towers { WaveManager.EnemiesKilled++; GameManager.EnemyWasDestroyed(Enemy.EnemyType); // resource acquisition if (Enemy.EnemyType == "Helicopter") { EffectManager.EffectCall(EffectManager.EffectEnums.Explosion, Enemy.ScreenPos - new Vector2((Art.Helicopter.Width / 4) / 2, Art.Helicopter.Height / 2), true); Sound.Explosion.Play(GameManager.MASTER_VOL * GameManager.SOUNDFX_VOL * 0.5f, 0f, 0f); } if (Enemy.EnemyType == "Transport") { for (float i = 0; i < 4; i++) { SpawnEnemy(SpawnSoldierString, Enemy.enemyVect - new Vector2(Enemy.Direction.X * -i / 4, Enemy.Direction.Y * -i / 4)); EffectManager.EffectCall(EffectManager.EffectEnums.Explosion, Enemy.ScreenPos - new Vector2(Art.Transport.Width / 2, Art.Transport.Height / 2), true); } Sound.Explosion.Play(GameManager.MASTER_VOL * GameManager.SOUNDFX_VOL * 0.5f, 0f, 0f); } else if (Enemy.EnemyType == "Tank") { for (float i = 0; i < 2; i++) { SpawnEnemy(SpawnSoldierString, Enemy.enemyVect - new Vector2(Enemy.Direction.X * -i / 4, Enemy.Direction.Y * -i / 4)); EffectManager.EffectCall(EffectManager.EffectEnums.Explosion, Enemy.ScreenPos - new Vector2(Art.TankBottom.Width / 2, Art.TankBottom.Height / 2), true); } Sound.Explosion.Play(GameManager.MASTER_VOL * GameManager.SOUNDFX_VOL * 0.5f, 0f, 0f); } else if (Enemy.EnemyType == "Jeep") { for (float i = 0; i < 1; i++) { SpawnEnemy(SpawnSoldierString, Enemy.enemyVect - new Vector2(Enemy.Direction.X * -i / 4, Enemy.Direction.Y * -i / 4)); EffectManager.EffectCall(EffectManager.EffectEnums.Explosion, Enemy.ScreenPos - new Vector2(Art.JeepBottom.Width / 2, Art.JeepBottom.Height / 2), true); } Sound.Explosion.Play(GameManager.MASTER_VOL * GameManager.SOUNDFX_VOL * 0.5f, 0f, 0f); } else if (Enemy.EnemyType == "Soldier") { EffectManager.EffectCall(EffectManager.EffectEnums.Blood, Enemy.ScreenPos + new Vector2(GameManager.rnd.Next(-5, 6), GameManager.rnd.Next(-5, 6)), false); if (GameManager.rnd.Next(1, 100) < 25) { Sound.WilhelmScream.Play(GameManager.MASTER_VOL * GameManager.SOUNDFX_VOL * 0.5f, 0f, 0f); } } } //DestroyEnemy(Enemy, Enemy.EnemyType, Enemy.EnemyID); EnemiesToRemove.Add(Enemy); } if (float.IsNaN(Enemy.enemyVect.X) || float.IsNaN(Enemy.enemyVect.Y)) // This needs testing... { //DestroyEnemy(Enemy, Enemy.EnemyType, Enemy.EnemyID); EnemiesToRemove.Add(Enemy); //WaveManager.WaveEnemiesUsed++; } else { Enemy.Update(GameManager.grid.gridStatus, gt); //updates the enemy } } foreach (Projectile proj in TankTurret.EnemyProjectiles) //updates the projectiles of enemy { proj.Update(); } // Remove Projectiles after lifetime. for (int i = 0; i < TankTurret.EnemyProjectiles.Count(); i++) { if (TankTurret.EnemyProjectiles[i].TimeSinceSpawn > TankTurret.EnemyProjectiles[i].Lifetime) { TankTurret.EnemyProjectiles.RemoveAt(i); } } foreach (Enemy enemy in EnemiesToAdd) { Enemies.Add(enemy); } foreach (Enemy enemy in EnemiesToRemove) { DestroyEnemy(enemy, enemy.EnemyType, enemy.EnemyID); } EnemiesToAdd.Clear(); EnemiesToRemove.Clear(); }