GameStateSplash.hpp
上传用户:zhj2929
上传日期:2022-07-23
资源大小:28772k
文件大小:5k
- #ifndef _GAME_STATES_SPLASH_H_
- #define _GAME_STATES_SPLASH_H_
- #include "GameState.h"
- #define SPLASH_DELAY 4000.0f
- #define SPLASH_DELAY_2 2000.0f
- #define GAMESCREEN_WIDTH 512
- #define GAMESCREEN_HEIGHT 480
- class MeshEffect;
- class GameStateSplash: public GameState
- {
- private:
- JTexture* mSplashTex;
- JQuad* mSplashQuad;
-
- int mStage;
- float mAlpha;
- float mTimer;
- float mDelta;
- float mMax;
- float mMaxDelta;
- MeshEffect* mEffect;
- JTexture* mBgTexture;
- JQuad* mBg;
- float caidanx1;
- float caidanx2;
- float caidanx3;
- float caidanx4;
- float caidanx5;
- float caidanx6;
- JLBFont* mPrint;
- JLBFont* mPrint2;
- JMusic* mMusic;
-
- JSample* snd2;
- int i;
- public:
- GameStateSplash(GameApp* app): GameState(app)
- {
- mEffect = NULL;
- mBgTexture = NULL;
- mBg = NULL;
- mSplashQuad = NULL;
- mMusic = NULL;
- snd2 =NULL;
- }
- virtual ~GameStateSplash()
- {
- }
- virtual void Create()
- {
- mSplashTex = mEngine->LoadTexture("Res/splash.png", true);
- mSplashQuad = new JQuad(mSplashTex, 0.0f, 0.0f, 332.0f, 180.0f);
- mBgTexture = mEngine->LoadTexture("backgroud/mubu.png", true);
- mBg = new JQuad(mBgTexture, 0.0f, 0.0f, GAMESCREEN_WIDTH,GAMESCREEN_HEIGHT);
- mPrint=new JLBFont("f3",16,true);
- mPrint2=new JLBFont("f3",16,true);
- mEffect = new MeshEffect(mSplashTex, 0, 0, 332, 180);
-
- mMusic = mEngine->LoadMusic("Res/smarioc.mod");
- snd2 = mEngine->LoadSample("music/menu.wav");
- }
-
- virtual void Destroy()
- {
- if (mSplashQuad)
- delete mSplashQuad;
- if (mSplashTex)
- mEngine->FreeTexture(mSplashTex);
- if (mEffect)
- delete mEffect;
- if (mBgTexture) delete mBgTexture;
- if (mBg) delete mBg;
- if (mPrint)
- delete mPrint;
- if (mPrint2)
- delete mPrint2;
- if (mMusic)
- mEngine->FreeMusic(mMusic);
- if (snd2)
- mEngine->FreeSample(snd2);
- }
-
- virtual void Start()
- {
- mStage = 0;
- mAlpha = 0.0f;
-
- mMax = 16.0f;
- mMaxDelta = 16.0f/SPLASH_DELAY;
- mDelta = 255/SPLASH_DELAY;
- mEffect->SetMax(mMax);
- mEffect->SetAlpha(mAlpha);
- mEffect->SetPosition(100.0f, 100.0f);
- caidanx1=500.0f;
- caidanx2=500.0f;
- caidanx3=500.0f;
- caidanx4=0.0f;
- caidanx5=0.0f;
- caidanx6=0.0f;
- i=1;
-
- mEngine->EnableVSync(true);
- }
- virtual void End()
- {
- mEngine->EnableVSync(false);
- //mEngine->StopMusic();
- mEngine->FreeMusic(mMusic);
- mMusic = NULL;
- }
- virtual void Update()
- {
- float dt = mEngine->GetDelta();
- if (mEngine->GetButtonClick(PSP_CTRL_START))
- {
- mEngine->PlaySample(snd2);
-
- if(i==1)
- {
- mApp->SetNextState(GAME_STATE_LOADING);
- }
- else if(i==2)
- {
- mApp->LoadGameStateHelp();
- mApp->SetNextState(GAME_STATE_HELP);
- }
- else if(i==3)
- {
- mEngine->End();
- }
- return;
- }
- if (mEngine->GetButtonClick(PSP_CTRL_DOWN))
- {
- mEngine->PlaySample(snd2);
-
- i++;
- if(i==4)
- i=1;
- }
- else if (mEngine->GetButtonClick(PSP_CTRL_UP))
- {
- mEngine->PlaySample(snd2);
-
- i--;
- if(i==0)
- i=3;
- }
-
- if (mStage == 0)
- {
- caidanx1=caidanx1-3;
- caidanx2=caidanx2-3;
- caidanx3=caidanx3-3;
- caidanx4=caidanx4+3;
- caidanx5=caidanx5+3;
- caidanx6=caidanx6+3;
- mAlpha += mDelta*dt;
- if (mAlpha > 255.0f)
- {
- mAlpha = 255.0f;
- }
- mMax -= mMaxDelta*dt;
- if (mMax<0.0f)
- {
- mMax = 0.0f;
- mStage = 1;
- mEngine->PlayMusic(mMusic);
- }
- mEffect->SetMax(mMax);
- mEffect->SetAlpha(mAlpha);
- mEffect->Update(dt);
- }
- else
- {
- //重新设定菜单选项的位置
- caidanx1=240.0f;
- caidanx2=240.0f;
- caidanx3=240.0f;
- }
- }
- virtual void Render()
- {
- mEngine->ClearScreen(ARGB(255,255,255,255));
- mEngine->RenderQuad(mBg, 0.0f, 0.0f);
- mEffect->Render();
- mPrint->SetColor(ARGB(255,90,240,120));
- mPrint2->SetColor(ARGB(255,255,255,255));
- if (mStage == 0)
- {
- mPrint->printf(caidanx1,280.0f,"%s", "Play");
- mPrint->printf(caidanx2,320.0f,"%s", "Instructions");
- mPrint->printf(caidanx3,360.0f,"%s", "Exit");
- mPrint->printf(caidanx4,280.0f,"%s", "Play");
- mPrint->printf(caidanx5,320.0f,"%s", "Instructions");
- mPrint->printf(caidanx6,360.0f,"%s", "Exit");
- }
- else if (mStage == 1)
- {
-
- if(i==1)
- {
- mPrint2->printf(caidanx1,280.0f,"%s", "Play");
- mPrint->printf(caidanx2,320.0f,"%s", "Instructions");
- mPrint->printf(caidanx3,360.0f,"%s", "Exit");
- }
- else if(i==2)
- {
- mPrint->printf(caidanx1,280.0f,"%s", "Play");
- mPrint2->printf(caidanx2,320.0f,"%s", "Instructions");
- mPrint->printf(caidanx3,360.0f,"%s", "Exit");
- }
- else if(i==3)
- {
- mPrint->printf(caidanx1,280.0f,"%s", "Play");
- mPrint->printf(caidanx2,320.0f,"%s", "Instructions");
- mPrint2->printf(caidanx3,360.0f,"%s", "Exit");
- }
- }
- }
- };
- #endif