/// <summary> /// Update the enemy. /// </summary> /// <param name="i_GameTime">Game time.</param> public override void Update(GameTime i_GameTime) { base.Update(i_GameTime); if (m_lastShotTime == TimeSpan.Zero) { m_lastShotTime = i_GameTime.TotalGameTime; updateNextShot(); } else if (!IsDead) { if (i_GameTime.TotalGameTime - m_lastShotTime > m_nextShotInterval) { m_lastShotTime = i_GameTime.TotalGameTime; Bullet bullet = null; bullet = new Bullet(GameScreen, CurrentLocation, Game.Window.ClientBounds.Bottom); if (m_shooter.Shoot(i_GameTime.TotalGameTime, bullet)) { SoundManager soundManager = Game.Services.GetService(typeof(SoundManager)) as SoundManager; soundManager.PlaySoundEffect(eSounds.EnemyGunShot); GameScreen.AddComponents(bullet); updateNextShot(); } else { bullet.Dispose(); bullet = null; } } } }
/// <summary> /// Initialize EnemiesMatrix components. /// </summary> public override void Initialize() { if (!m_isInitialized) { m_isInitialized = true; foreach (Enemy enemy in m_enemies) { m_gameScreen.AddComponents(enemy); enemy.BeenKilled += () => enemyDead(enemy); } } }
/// <summary> /// Initialize the BarriersArray. /// </summary> public override void Initialize() { if (!m_isInitialized) { m_isInitialized = true; m_gameScreen.AddComponents(m_barriers); m_midX = (Game.Window.ClientBounds.Width - m_totalWidth) / 2; m_baseVectorForBarriersLocation.X = m_midX; m_baseVectorForBarriersLocation.Y = Game.Window.ClientBounds.Height - Spaceship.sr_SpaceshipSize - Barrier.sr_BarrierHeight; foreach (Barrier barrier in m_barriers) { barrier.SetZeroVector(m_baseVectorForBarriersLocation); } } }
/// <summary> /// Allow the spaceship to shoot a HurtableBullet. /// </summary> /// <param name="i_GameTime">Current time.</param> /// <returns>The HurtableBullet that were shot.</returns> private void shoot(GameTime i_GameTime) { HurtableBullet bullet = new HurtableBullet(GameScreen, m_selfLocation); if (m_shooter.Shoot(i_GameTime.TotalGameTime, bullet)) { bullet.GetScore += GetAdditionalScore; GameScreen.AddComponents(bullet); SoundManager soundManager = Game.Services.GetService(typeof(SoundManager)) as SoundManager; soundManager.PlaySoundEffect(eSounds.SSGunShot); } else { bullet.Dispose(); bullet = null; } }