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

游戏引擎

开发平台:

Visual C++

  1. // TempMenu.cpp: implementation of the CTempMenu class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "TempMenu.h"
  6. #include "texmanager.h"
  7. #include "audio.h"
  8. #include "input.h"
  9. #include "gamesetting.h"
  10. //////////////////////////////////////////////////////////////////////
  11. // Construction/Destruction
  12. //////////////////////////////////////////////////////////////////////
  13. CTempMenu::CTempMenu()
  14. {
  15.     m_cTempSheet=NULL;
  16. m_cOptionsSheet=NULL;
  17. m_bActivate=false;
  18. m_bResource=false;
  19. }
  20. CTempMenu::~CTempMenu()
  21. {
  22. DeleteMenu();
  23. }
  24. bool  CTempMenu::LoadMenu()
  25. {
  26. if(m_bResource)return true;
  27. //////// Texture
  28. CTexManager cTexManager;
  29. if(!cTexManager.CreateTempMenuResource())
  30.         MessageBox(0, "Create textures error", "Error", MB_OK | MB_ICONERROR);
  31.     //////////////Cursor and background
  32. m_texCursor = cTexManager.GetTextureID(TEX_MENU_CURSOR);
  33. m_texBkg    = cTexManager.GetTextureID(TEX_SCREEN_CAPTURE);
  34. ///////////////////Sheets
  35.     m_cTempSheet         = new CTempSheet;
  36. m_cOptionsSheet      = new COptionsSheet;
  37.   m_cTempSheet->InitSheet();
  38. m_cOptionsSheet->InitSheet();
  39.     m_cTempSheet->m_bActive=true;
  40. ///////// sound 
  41. CAudio audio;
  42. audio.CreateSound(MENU_SOUND_CLICK,"audio/menu/click.wav",false);
  43. audio.CreateSound(MENU_SOUND_TEST,"audio/ambient/bird0.wav",false);
  44.     ///////////////////////////////
  45. m_bActivate=true;
  46. m_bResource=true;
  47. return true;
  48. }
  49. void  CTempMenu::DeleteMenu()
  50. {
  51. if(!m_bResource)return;
  52. //////// delete Texture
  53. CTexManager cTexManager;
  54. cTexManager.DeleteTempMenuResource();
  55.     ////////// sheets
  56.     if(m_cTempSheet !=NULL)
  57. {
  58. delete m_cTempSheet;
  59. m_cTempSheet=NULL;
  60. }
  61. if(m_cOptionsSheet  !=NULL) 
  62. {
  63. delete m_cOptionsSheet;
  64. m_cOptionsSheet=NULL;
  65. }
  66. ///////////////// delete audio
  67. CAudio audio;
  68. audio.DeleteSound(MENU_SOUND_CLICK);
  69. audio.DeleteSound(MENU_SOUND_TEST);
  70. //////////////////////////////
  71. m_bActivate=false;
  72. m_bResource=false;
  73. }
  74. void CTempMenu::RenderMenu()
  75. {
  76. if(!m_bActivate)return;
  77. UpdateMenu();
  78. DrawBackGround();
  79. /////////////////////////////////////
  80. m_cTempSheet->RenderSheet();
  81. m_cOptionsSheet->RenderSheet();
  82. //////////////////////////////
  83. if(CInput::m_bShowMouse)DrawCursor();
  84. }
  85. void CTempMenu::UpdateMenu()
  86. {
  87. if(m_cTempSheet->m_bActive)
  88. {
  89. if(m_cTempSheet->m_iSelect==0)
  90. {
  91.             m_cTempSheet->m_iSelect=-1;
  92. CGameSetting::m_iGameState=GAME_MISSION;
  93. }
  94. if(m_cTempSheet->m_iSelect==3)
  95. {
  96.             m_cTempSheet->m_iSelect=-1;
  97. m_cTempSheet->m_bActive=false;
  98. m_cOptionsSheet->m_bActive=true;
  99. }
  100. if(m_cTempSheet->m_iSelect==4)
  101. {
  102. CGameSetting::m_iGameState=GAME_MAIN_MENU;
  103. }
  104. }
  105. if(m_cOptionsSheet->m_bActive)
  106. {
  107. if(m_cOptionsSheet->m_iSelect==0  || m_cOptionsSheet->m_iSelect==2)
  108. {
  109. m_cOptionsSheet->m_iSelect=-1;
  110. m_cOptionsSheet->m_bActive=false;
  111. m_cTempSheet->m_bActive=true;
  112. }
  113. }
  114. }
  115. void  CTempMenu::DrawBackGround()
  116. {
  117. static float move=0;
  118. // move+=0.01f;
  119. if(move>1)move=0;
  120.       glBindTexture(GL_TEXTURE_2D, m_texBkg);
  121.     glEnable(GL_TEXTURE_2D);
  122. glColor3f(1,1,1);
  123.       glBegin(GL_QUADS);
  124.           glTexCoord2f(move,1);    
  125.         glVertex3i(-400 , 300 , -520);
  126.         glTexCoord2f(1+move,1);   
  127.         glVertex3i(400 , 300 , -520);
  128.     glTexCoord2f(1+move,0);   
  129.         glVertex3i(400 , -300 , -520);
  130.     glTexCoord2f(move,0);    
  131.         glVertex3i(-400 , -300 , -520);
  132.     glEnd();
  133.     glDisable(GL_TEXTURE_2D);
  134. }
  135. void  CTempMenu::DrawCursor()
  136. {
  137.      glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  138.     glEnable(GL_BLEND);
  139.       glBindTexture(GL_TEXTURE_2D, m_texCursor);
  140.     glEnable(GL_TEXTURE_2D);
  141. glColor3f(1,1,1);
  142.       glBegin(GL_QUADS);
  143.           glTexCoord2f(0,1);    
  144.         glVertex3i(m_cInput.m_mousePosX-400 , 300-m_cInput.m_mousePosY , -520);
  145.         glTexCoord2f(1,1);   
  146.         glVertex3i(m_cInput.m_mousePosX+16-400 , 300-m_cInput.m_mousePosY , -520);
  147.     glTexCoord2f(1,0);   
  148.         glVertex3i(m_cInput.m_mousePosX+16-400 , 300-m_cInput.m_mousePosY-16 , -520);
  149.     glTexCoord2f(0,0);    
  150.         glVertex3i(m_cInput.m_mousePosX-400 , 300-m_cInput.m_mousePosY-16 , -520);
  151.     glEnd();
  152.     glDisable(GL_TEXTURE_2D);
  153.     glDisable(GL_BLEND);
  154. }