AudioManager.cpp
上传用户:hkb425
上传日期:2007-06-16
资源大小:34191k
文件大小:5k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. // AudioManager.cpp: implementation of the CAudioManager class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "AudioManager.h"
  6. #include "MediaPlayer.h"
  7. #include "GameSetting.h"
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11. CAudioManager::CAudioManager()
  12. {
  13. }
  14. CAudioManager::~CAudioManager()
  15. {
  16. }
  17. void CAudioManager::InitCheck()
  18. {
  19.     CGameSetting cGameSetting;
  20.     CAudio       cAudio;
  21.     CMediaPlayer cMusic;
  22. if(cAudio.IsAudioEnable() && cMusic.IsMediaEnable())
  23. cGameSetting.m_bAudioEnable=true;
  24. else 
  25. {
  26.         MessageBox(NULL, "Audio Invalidate !", "Warning", MB_OK);
  27. cGameSetting.m_bAudioEnable=false;
  28. cGameSetting.m_bMusic=false;
  29. cGameSetting.m_bSound=false;
  30. }
  31. if(cGameSetting.m_bMusic)cMusic.SetMediaActive(true);
  32. else cMusic.SetMediaActive(false);
  33. if(cGameSetting.m_bSound)cAudio.SetAudioActive(true);
  34. else cAudio.SetAudioActive(false);
  35. cMusic.SetVolume(cGameSetting.m_iMusicVolume);
  36. cAudio.SetVolume(cGameSetting.m_iSoundVolume);
  37. }
  38. bool CAudioManager::CreateMenuResource()
  39. {
  40.     CAudio       cAudio;
  41.     CMediaPlayer cMusic;
  42.     ////////////music
  43. if(!cMusic.CreateMusic("audio/music/menu.mp3"))
  44. {
  45. // MessageBox(0, "Unable to load  audio/menu.mp3", "Error", MB_OK | MB_ICONERROR);
  46. }
  47. // cMusic.SetVolume(cGameSetting.m_iMusicVolume);
  48. //////////// Sound
  49. cAudio.CreateSound(MENU_SOUND_CLICK,"audio/menu/click.wav",false);
  50. cAudio.CreateSound(MENU_SOUND_TEST,"audio/ambient/bird0.wav",false);
  51.     ///////////////////////////////
  52. cMusic.Play();
  53. return true;
  54. }
  55. void CAudioManager::DeleteMenuResource()
  56. {
  57.     CMediaPlayer cMusic;
  58. cMusic.Stop();
  59. CAudio audio;
  60. audio.StopAll();
  61. audio.DeleteSound(MENU_SOUND_CLICK);
  62. audio.DeleteSound(MENU_SOUND_TEST);
  63. }
  64. ////////////////////////////////////////////////
  65. bool CAudioManager::CreateMissionResource()
  66. {
  67.     CAudio       cAudio;
  68. cAudio.CreateSound(SOUND_RUN_0,"audio/soldier/run0.wav",true);
  69. cAudio.CreateSound(SOUND_RUN_1,"audio/soldier/run1.wav",true);
  70. cAudio.CreateSound(SOUND_RUN_2,"audio/soldier/run2.wav",true);
  71. cAudio.CreateSound(SOUND_RUN_3,"audio/soldier/run3.wav",true);
  72. cAudio.CreateSound(SOUND_AMBIENT,"audio/ambient/ambient.wav",false);
  73. cAudio.CreateSound(SOUND_BIRD_0, "audio/ambient/bird0.wav",false);
  74. cAudio.CreateSound(SOUND_BIRD_1, "audio/ambient/bird1.wav",false);
  75. cAudio.CreateSound(SOUND_BIRD_2, "audio/ambient/bird2.wav",false);
  76. cAudio.CreateSound(SOUND_BIRD_3, "audio/ambient/bird3.wav",false);
  77. cAudio.CreateSound(SOUND_BIRD_4, "audio/ambient/bird4.wav",false);
  78. cAudio.CreateSound(SOUND_BIRD_5, "audio/ambient/bird5.wav",false);
  79. cAudio.CreateSound(SOUND_BIRD_6, "audio/ambient/bird6.wav",false);
  80. cAudio.CreateSound(SOUND_BIRD_7, "audio/ambient/bird7.wav",false);
  81. cAudio.CreateSound(SOUND_GUN_SINGLE, "audio/weapon/singleSound.wav",false);
  82. cAudio.CreateSound(SOUND_GUN_MULTI,  "audio/weapon/multiSound.wav",false);
  83. cAudio.CreateSound(SOUND_GUN_RIFLE,  "audio/weapon/gunShot.wav",true);
  84. cAudio.CreateSound(SOUND_BULLET_WHIZ,  "audio/weapon/whiz.wav",false);
  85. cAudio.CreateSound(SOUND_PAIN_1,  "audio/soldier/pain1.wav",true);
  86. cAudio.CreateSound(SOUND_PAIN_2,  "audio/soldier/pain2.wav",true);
  87. cAudio.CreateSound(SOUND_PAIN_3,  "audio/soldier/pain3.wav",true);
  88. cAudio.CreateSound(SOUND_DEATH_1,  "audio/soldier/death1.wav",true);
  89. cAudio.CreateSound(SOUND_DEATH_2,  "audio/soldier/death2.wav",true);
  90. cAudio.CreateSound(SOUND_DEATH_3,  "audio/soldier/death3.wav",true);
  91.     CMediaPlayer cMusic;
  92. cMusic.Play();
  93.     return true;
  94. }
  95. void CAudioManager::DeleteMissionResource()
  96. {
  97.     CMediaPlayer cMusic;
  98. cMusic.Stop();
  99. CAudio       cAudio;
  100. cAudio.StopAll();
  101. cAudio.DeleteSound(SOUND_RUN_0);
  102. cAudio.DeleteSound(SOUND_RUN_1);
  103. cAudio.DeleteSound(SOUND_RUN_2);
  104. cAudio.DeleteSound(SOUND_RUN_3);
  105. cAudio.DeleteSound(SOUND_AMBIENT);
  106. cAudio.DeleteSound(SOUND_BIRD_0);
  107. cAudio.DeleteSound(SOUND_BIRD_1);
  108. cAudio.DeleteSound(SOUND_BIRD_2);
  109. cAudio.DeleteSound(SOUND_BIRD_3);
  110. cAudio.DeleteSound(SOUND_BIRD_4);
  111. cAudio.DeleteSound(SOUND_BIRD_5);
  112. cAudio.DeleteSound(SOUND_BIRD_6);
  113. cAudio.DeleteSound(SOUND_BIRD_7);
  114. cAudio.DeleteSound(SOUND_GUN_SINGLE);
  115. cAudio.DeleteSound(SOUND_GUN_MULTI);
  116. cAudio.DeleteSound(SOUND_GUN_RIFLE);
  117. cAudio.DeleteSound(SOUND_BULLET_WHIZ);
  118. cAudio.DeleteSound(SOUND_PAIN_1);
  119. cAudio.DeleteSound(SOUND_PAIN_2);
  120. cAudio.DeleteSound(SOUND_PAIN_3);
  121. cAudio.DeleteSound(SOUND_DEATH_1);
  122. cAudio.DeleteSound(SOUND_DEATH_2);
  123. cAudio.DeleteSound(SOUND_DEATH_3);
  124. }