Now, it is time to add concurrent sound effects associated to game events.
1. Stay in the
3DInvadersSilverlight
project.2. Open
InvadersGame.cs
.3. Add the following
private
variable to hold theSoundManager
instance:private SoundManager _soundManager;
4. Add the following
private
method to create and initialize the sound manger related to the game:private void InitializeSoundManager() { _soundManager = new SoundManager(_mainPage.LayoutRoot); _soundManager.Volume = 1; }
5. Add the following lines of code after the line
base.Initialize()
; in theInitialize
method:InitializeSoundManager();
6. Now, add the following lines of code before the end of the
UpdateWithTime
method (a random thunder):if (_random.Next(20) == 2) _soundManager.PlayThunder();
7. Replace the code that checks the
Key.I
key in theCheckKeyboard
method with these lines:if (KeyboardManager.IsKeyDown(Key.I)) { _ufo1.Body.ApplyImpulse(_levelImpulse); // Play a sound when...