GameStateSplash.hpp
上传用户:zhj2929
上传日期:2022-07-23
资源大小:28772k
文件大小:5k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. #ifndef _GAME_STATES_SPLASH_H_
  2. #define _GAME_STATES_SPLASH_H_
  3. #include "GameState.h"
  4. #define SPLASH_DELAY 4000.0f
  5. #define SPLASH_DELAY_2 2000.0f
  6. #define GAMESCREEN_WIDTH  512
  7. #define GAMESCREEN_HEIGHT 480
  8. class MeshEffect;
  9. class GameStateSplash: public GameState
  10. {
  11. private:
  12. JTexture* mSplashTex;
  13. JQuad* mSplashQuad;
  14. int mStage;
  15. float mAlpha;
  16. float mTimer;
  17. float mDelta;
  18. float mMax;
  19. float mMaxDelta;
  20. MeshEffect* mEffect;
  21. JTexture* mBgTexture;
  22. JQuad* mBg;
  23. float caidanx1;
  24.     float caidanx2;
  25. float caidanx3;
  26. float caidanx4;
  27.     float caidanx5;
  28. float caidanx6;
  29. JLBFont* mPrint;
  30. JLBFont* mPrint2;
  31. JMusic* mMusic;
  32.  
  33. JSample* snd2;
  34. int i;
  35. public:
  36. GameStateSplash(GameApp* app): GameState(app) 
  37. {
  38. mEffect = NULL;
  39.         mBgTexture = NULL;
  40. mBg = NULL;
  41. mSplashQuad = NULL;
  42. mMusic = NULL;
  43. snd2 =NULL;
  44. }
  45. virtual ~GameStateSplash() 
  46. {
  47. }
  48. virtual void Create() 
  49. {
  50. mSplashTex = mEngine->LoadTexture("Res/splash.png", true);
  51. mSplashQuad = new JQuad(mSplashTex, 0.0f, 0.0f, 332.0f, 180.0f);
  52. mBgTexture = mEngine->LoadTexture("backgroud/mubu.png", true);
  53.         mBg = new JQuad(mBgTexture, 0.0f, 0.0f, GAMESCREEN_WIDTH,GAMESCREEN_HEIGHT);
  54. mPrint=new JLBFont("f3",16,true);
  55. mPrint2=new JLBFont("f3",16,true);
  56. mEffect = new MeshEffect(mSplashTex, 0, 0, 332, 180);
  57. mMusic = mEngine->LoadMusic("Res/smarioc.mod");
  58. snd2 = mEngine->LoadSample("music/menu.wav");
  59. }
  60. virtual void Destroy() 
  61. {
  62. if (mSplashQuad)
  63. delete mSplashQuad;
  64. if (mSplashTex)
  65. mEngine->FreeTexture(mSplashTex);
  66. if (mEffect)
  67. delete mEffect;
  68.         if (mBgTexture) delete mBgTexture;
  69. if (mBg) delete mBg;
  70. if (mPrint)
  71. delete mPrint;
  72. if (mPrint2)
  73. delete mPrint2;
  74. if (mMusic)
  75. mEngine->FreeMusic(mMusic);
  76. if (snd2)
  77. mEngine->FreeSample(snd2);
  78. }
  79. virtual void Start()
  80. {
  81. mStage = 0;
  82. mAlpha = 0.0f;
  83. mMax = 16.0f;
  84. mMaxDelta = 16.0f/SPLASH_DELAY;
  85. mDelta = 255/SPLASH_DELAY;
  86. mEffect->SetMax(mMax);
  87. mEffect->SetAlpha(mAlpha);
  88. mEffect->SetPosition(100.0f, 100.0f);
  89. caidanx1=500.0f;
  90.         caidanx2=500.0f;
  91.         caidanx3=500.0f;
  92. caidanx4=0.0f;
  93.         caidanx5=0.0f;
  94.         caidanx6=0.0f;
  95. i=1;
  96. mEngine->EnableVSync(true);
  97. }
  98. virtual void End()
  99. {
  100. mEngine->EnableVSync(false);
  101. //mEngine->StopMusic();
  102. mEngine->FreeMusic(mMusic);
  103. mMusic = NULL;
  104. }
  105. virtual void Update()
  106. {
  107. float dt = mEngine->GetDelta();
  108. if (mEngine->GetButtonClick(PSP_CTRL_START))
  109. {
  110. mEngine->PlaySample(snd2);
  111. if(i==1)
  112. {
  113.                 mApp->SetNextState(GAME_STATE_LOADING);
  114. }
  115. else if(i==2)
  116. {
  117.    mApp->LoadGameStateHelp();
  118.                mApp->SetNextState(GAME_STATE_HELP);
  119. }
  120. else if(i==3)
  121. {
  122.                 mEngine->End();
  123. }
  124. return;
  125. }
  126. if (mEngine->GetButtonClick(PSP_CTRL_DOWN))
  127. {
  128. mEngine->PlaySample(snd2);
  129. i++;
  130. if(i==4)
  131. i=1;
  132. }
  133. else if (mEngine->GetButtonClick(PSP_CTRL_UP))
  134. {
  135. mEngine->PlaySample(snd2);
  136. i--;
  137. if(i==0)
  138. i=3;
  139. }
  140.         
  141. if (mStage == 0)
  142. {
  143. caidanx1=caidanx1-3;
  144.         caidanx2=caidanx2-3;
  145.         caidanx3=caidanx3-3;
  146. caidanx4=caidanx4+3;
  147.         caidanx5=caidanx5+3;
  148.         caidanx6=caidanx6+3;
  149. mAlpha += mDelta*dt;
  150. if (mAlpha > 255.0f)
  151. {
  152. mAlpha = 255.0f;
  153. }
  154. mMax -= mMaxDelta*dt;
  155. if (mMax<0.0f)
  156. {
  157. mMax = 0.0f;
  158. mStage = 1;
  159. mEngine->PlayMusic(mMusic);
  160. }
  161. mEffect->SetMax(mMax);
  162. mEffect->SetAlpha(mAlpha);
  163. mEffect->Update(dt);
  164. }
  165. else
  166. {
  167. //重新设定菜单选项的位置
  168.             caidanx1=240.0f;
  169. caidanx2=240.0f;
  170. caidanx3=240.0f;
  171. }
  172. }
  173. virtual void Render() 
  174. {
  175. mEngine->ClearScreen(ARGB(255,255,255,255));
  176. mEngine->RenderQuad(mBg, 0.0f, 0.0f);
  177. mEffect->Render();
  178. mPrint->SetColor(ARGB(255,90,240,120));
  179. mPrint2->SetColor(ARGB(255,255,255,255));
  180.        if (mStage == 0)
  181.    {
  182.    mPrint->printf(caidanx1,280.0f,"%s", "Play");
  183.            mPrint->printf(caidanx2,320.0f,"%s", "Instructions");
  184.    mPrint->printf(caidanx3,360.0f,"%s", "Exit");
  185.    mPrint->printf(caidanx4,280.0f,"%s", "Play");
  186.            mPrint->printf(caidanx5,320.0f,"%s", "Instructions");
  187.    mPrint->printf(caidanx6,360.0f,"%s", "Exit");
  188.    }
  189.    else if (mStage == 1)
  190.    {
  191.            if(i==1)
  192.    {
  193.   mPrint2->printf(caidanx1,280.0f,"%s", "Play");
  194.               mPrint->printf(caidanx2,320.0f,"%s", "Instructions");
  195.       mPrint->printf(caidanx3,360.0f,"%s", "Exit");
  196.    }
  197.    else if(i==2)
  198.    {
  199.               mPrint->printf(caidanx1,280.0f,"%s", "Play");
  200.               mPrint2->printf(caidanx2,320.0f,"%s", "Instructions");
  201.       mPrint->printf(caidanx3,360.0f,"%s", "Exit");
  202.    }
  203.    else if(i==3)
  204.    {
  205.   mPrint->printf(caidanx1,280.0f,"%s", "Play");
  206.               mPrint->printf(caidanx2,320.0f,"%s", "Instructions");
  207.       mPrint2->printf(caidanx3,360.0f,"%s", "Exit");
  208.    }
  209. }
  210. }
  211. };
  212. #endif