GameStateLogo.hpp
上传用户:zhj2929
上传日期:2022-07-23
资源大小:28772k
文件大小:11k
- #ifndef _GAME_STATES_LOGO_H_
- #define _GAME_STATES_LOGO_H_
- #include "GameState.h"
- #include "../../JGE/HGE/include/hgesprite.h"
- #include "../../JGE/HGE/include/hgeparticle.h"
- #define SPLASH_DELAY 4000.0f
- #define SPLASH_DELAY_2 2000.0f
- #define GAMESCREEN_WIDTH 512
- #define GAMESCREEN_HEIGHT 480
- extern HGE *hge;
- class GameStateLogo: public GameState
- {
- private:
- int mMode;
- int mStage;
- float mAlpha;
- float mTimer;
- float mDelta;
- //控制背景小图片的渲染的y坐标
- float mBgY;
- float x, y;
- //记录渲染的图片序列号
- int number;
- //控制渲染速度
- int rendspeed;
- //站立还是行走
- int StandOrWalk;
- int JumpOrParticle;
- //加载马里奥脸部朝向后边的一组图像的图片
- JTexture* texB;
- HTEXTURE tex;//加载精灵图片的指针
- JTexture* quadTex;//背景图片
- JTexture* logoTex;//logo图片
- //背景
- JQuad* quad;
- JSprite* mstand1;
- JSprite* mjump;
- JSprite* mwalk1;
- JSprite* mwalk2;
- JSprite* logo;
- hgeSprite* spt;
-
- hgeParticleSystem * par1;
- hgeParticleSystem * par2;
-
- hgeParticleSystem * par3;//加载菜单粒子特效系统的指针
- hgeParticleSystem * par4;//加载菜单粒子特效系统的指针
- hgeParticleSystem * par5;//加载菜单粒子特效系统的指针
- hgeParticleSystem * par6;
- hgeParticleSystem * par7;
- hgeParticleSystem * par8;
- hgeParticleSystem * par9;
- hgeParticleSystem * par10;
- hgeParticleSystem * par11;
- hgeParticleSystem * par12;
- hgeParticleSystem * par13;
- hgeParticleSystem * par14;
- hgeParticleSystem * par15;
- hgeParticleSystem * par16;
- hgeParticleSystem * par17;
- hgeParticleSystem * par18;
- float caidanx1;
- float caidanx2;
- float caidanx3;
- float logoX;
- public:
- GameStateLogo(GameApp* app): GameState(app)
- {
- }
- virtual ~GameStateLogo()
- {
- }
- virtual void Create()
- {
- mEngine->LoadMP3("music/logo.mp3");
- texB = mEngine->LoadTexture("mario/all-supermario3.png", true);
- quadTex = mEngine->LoadTexture("backgroud/snow.png", true);
- logoTex = mEngine->LoadTexture("logo/logo.png", true);
- quad = new JQuad(quadTex, 0.0f, 0.0f, GAMESCREEN_WIDTH, GAMESCREEN_HEIGHT);
- mstand1 = new JSprite(texB,502,0,100,100);
- mjump = new JSprite(texB,100,0,100,100);
- mwalk1 = new JSprite(texB,400,0,100,100);
- mwalk2 = new JSprite(texB,600,0,100,100);
- logo = new JSprite(logoTex,0,0,158,158);
- mstand1->SetHotSpot(50,50);
- mjump->SetHotSpot(50,50);
- mwalk1->SetHotSpot(50,50);
- mwalk2->SetHotSpot(50,50);
- logo->SetHotSpot(80,80);
- //粒子的渲染图形
- tex=hge->Texture_Load("particle/particles.png");
- //如果加载失败,则弹出提示窗口
- if(!tex)
- {
- MessageBox(NULL, "Can't load particles.png", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
- }
- //设置粒子的渲染图形
- spt=new hgeSprite(tex, 32, 32, 32, 32);
- spt->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE);
- spt->SetHotSpot(16,16);
-
- //初始化粒子系统,并点燃粒子系统
- par1=new hgeParticleSystem("trail.psi",spt);
- par1->MoveTo(550,490);
- par1->Fire();
- par2=new hgeParticleSystem("trail.psi",spt);
- par2->MoveTo(550,490);
- par2->Fire();
- par3=new hgeParticleSystem("trail.psi",spt);
- par3->MoveTo(caidanx1+30,255);
- par3->Fire();
- par4=new hgeParticleSystem("trail.psi",spt);
- par4->MoveTo(caidanx2+70,295);
- par4->Fire();
- par5=new hgeParticleSystem("trail.psi",spt);
- par5->MoveTo(caidanx3+25,335);
- par5->Fire();
- par6=new hgeParticleSystem("trail.psi",spt);
- par6->MoveTo(550,490);
- par6->Fire();
- par7=new hgeParticleSystem("trail.psi",spt);
- par7->MoveTo(550,490);
- par7->Fire();
- par8=new hgeParticleSystem("trail.psi",spt);
- par8->MoveTo(550,490);
- par8->Fire();
- par9=new hgeParticleSystem("trail.psi",spt);
- par9->MoveTo(550,490);
- par9->Fire();
- par10=new hgeParticleSystem("trail.psi",spt);
- par10->MoveTo(550,490);
- par10->Fire();
- par11=new hgeParticleSystem("trail.psi",spt);
- par11->MoveTo(550,490);
- par11->Fire();
- par12=new hgeParticleSystem("trail.psi",spt);
- par12->MoveTo(550,490);
- par12->Fire();
- par13=new hgeParticleSystem("trail.psi",spt);
- par13->MoveTo(550,490);
- par13->Fire();
- par14=new hgeParticleSystem("trail.psi",spt);
- par14->MoveTo(550,490);
- par14->Fire();
- par15=new hgeParticleSystem("trail.psi",spt);
- par15->MoveTo(550,490);
- par15->Fire();
- par16=new hgeParticleSystem("trail.psi",spt);
- par16->MoveTo(550,490);
- par16->Fire();
- par17=new hgeParticleSystem("trail.psi",spt);
- par17->MoveTo(550,490);
- par17->Fire();
- par18=new hgeParticleSystem("trail.psi",spt);
- par18->MoveTo(550,490);
- par18->Fire();
- }
-
- virtual void Destroy()
- {
- if (texB)
- mEngine->FreeTexture(texB);
- if (quadTex)
- mEngine->FreeTexture(quadTex);
- if (quad) delete quad;
- if (mstand1) delete mstand1;
- if (mjump) delete mjump;
- if (mwalk1) delete mwalk1;
- if (mwalk2) delete mwalk2;
- if (logoTex) delete logoTex;
- if (logo) delete logo;
-
- //if (parQuad) delete parQuad;
- if (par1) delete par1;
- if (par2) delete par2;
- if (par3) delete par3;
- if (par4) delete par4;
- if (par5) delete par5;
- if (par6) delete par6;
- if (par7) delete par7;
- if (par8) delete par8;
- if (par9) delete par9;
- if (par10) delete par10;
- if (par11) delete par11;
- if (par12) delete par12;
- if (par13) delete par13;
- if (par14) delete par14;
- if (par15) delete par15;
- if (par16) delete par16;
- if (par17) delete par17;
- if (par18) delete par18;
- if(spt) delete spt;
- hge->Texture_Free(tex);
- }
-
- virtual void Start()
- {
- mMode = 0;
- mStage = 0;
- mAlpha = 0.0f;
- mBgY = 0.0f;
- x=450.0f;
- y=100.0f;
- //记录渲染的图片序列号
- number=1;
- //调用15次框架函数之后,再渲染另外的图片
- rendspeed=15;
- StandOrWalk = 1;//站立
- JumpOrParticle=1;//跳跃
- //菜单项的位置
- caidanx1=620.0f;
- caidanx2=620.0f;
- caidanx3=620.0f;
- logoX=600.0f;
- mDelta = 255/SPLASH_DELAY;
- mEngine->PlayMP3();
-
- mEngine->EnableVSync(true);
- }
- virtual void End()
- {
- mEngine->EnableVSync(false);
- mEngine->StopMP3();
- mEngine->FreeMP3();
- }
- virtual void Update()
- {
- float dt = mEngine->GetDelta();
- //Mario的更新动画
- if(x==450&&StandOrWalk<90)
- {
- StandOrWalk++;
- }
- else
- {
- if(x>150)
- {
- x=x-1.5f;
- }
- else
- {
- if(JumpOrParticle<50)
- {
- JumpOrParticle++;
- }
- else
- {
- //第一个粒子特效的控制
- par1->MoveTo(50,400);
- par1->MoveTo(80,200);
- par1->Update(dt);
- //第二个粒子特效的控制
- par2->MoveTo(80,200);
- par2->MoveTo(110,300);
- par2->Update(dt);
- //第六个粒子特效的控制
- par6->MoveTo(110,300);
- par6->MoveTo(140,200);
- par6->Update(dt);
- //第七个粒子特效的控制
- par7->MoveTo(140,200);
- par7->MoveTo(170,400);
- par7->Update(dt);
- par8->MoveTo(200,300);
- par8->MoveTo(220,400);
- par8->Update(dt);
- par9->MoveTo(220,400);
- par9->MoveTo(240,300);
- par9->Update(dt);
- par10->MoveTo(300,300);
- par10->MoveTo(270,300);
- par10->Update(dt);
- par11->MoveTo(270,300);
- par11->MoveTo(300,400);
- par11->Update(dt);
- par12->MoveTo(300,400);
- par12->MoveTo(270,400);
- par12->Update(dt);
- par13->MoveTo(340,200);
- par13->MoveTo(340,400);
- par13->Update(dt);
- par14->MoveTo(340,200);
- par14->MoveTo(430,200);
- par14->Update(dt);
- par15->MoveTo(430,200);
- par15->MoveTo(430,300);
- par15->Update(dt);
- par16->MoveTo(340,300);
- par16->MoveTo(430,300);
- par16->Update(dt);
- par17->MoveTo(430,300);
- par17->MoveTo(430,400);
- par17->Update(dt);
- par18->MoveTo(430,400);
- par18->MoveTo(340,400);
- par18->Update(dt);
- }
- x=150;
- }
- rendspeed--;
-
- if(JumpOrParticle==1)
- {
- caidanx1=caidanx1-4;
- caidanx2=caidanx2-4;
- caidanx3=caidanx3-4;
- logoX=logoX-4;
- par3->MoveTo(caidanx1+30,255);
- par3->MoveTo(caidanx1+80,255);
- par3->Update(dt);
- par4->MoveTo(caidanx2+70,295);
- par4->MoveTo(caidanx2+120,295);
- par4->Update(dt);
- par5->MoveTo(caidanx3+25,335);
- par5->MoveTo(caidanx3+75,335);
- par5->Update(dt);
- }
- }
- //背景的更新动画
- mBgY += 0.05f*dt;
- if (mBgY > 0.0f)
- mBgY = -60.0f;
- //--------------------------------------------------------
- if (mMode==0)
- {
- mAlpha += mDelta*dt;
-
- if (mAlpha > 255.0f)
- {
- mAlpha = 255.0f;
- mMode = 1;
- mTimer = 0.0f;
- }
- }
- else if (mMode==1)
- {
- mTimer += dt;
- if (mTimer > SPLASH_DELAY_2)
- mMode = 2;
- }
- else if (mMode==2)
- {
- mAlpha -= mDelta*dt;
- if (mAlpha < 0.0f)
- {
- mAlpha = 0.0f;
- mStage++;
- mMode = 3;
- mApp->SetNextState(GAME_STATE_SPLASH);
- }
- }
- else
- return;
- }
- virtual void Render()
- {
- mEngine->ClearScreen(ARGB(255,255,255,255));
- if (mMode == 3) return;
-
- //背景的渲染动画
- float bgx = 0.0f;
- float bgy = mBgY;
- for (int i=0;i<12;i++)
- {
- mEngine->RenderQuad(quad, bgx, bgy);
- bgy += 60.0f;
- }
- //渲染马里奥
- if(x==450&&StandOrWalk<90)
- {
- mstand1->SetPosition(x,y);
- mstand1->Render();
- }
- else
- {
- if(x>150&&number==1&&rendspeed)
- {
- mwalk1->SetPosition(x,y);
- mwalk1->Render();
- }
- else if(x>150&&number==2&&rendspeed)
- {
- mstand1->SetPosition(x,y);
- mstand1->Render();
- }
- else if(x>150&&number==3&&rendspeed)
- {
- mwalk2->SetPosition(x,y);
- mwalk2->Render();
- }
- else if(x>150&&number==4&&rendspeed)
- {
- mstand1->SetPosition(x,y);
- mstand1->Render();
- }
- else if(x==150)
- {
- mjump->SetPosition(x,y);
- mjump->Render();
- if(JumpOrParticle<50)
- {
- }
- else
- {
- //渲染粒子效果
- logo->SetPosition(350.0f,100.0f);
- logo->Render();
- par1->Render();
- par2->Render();
- par6->Render();
- par7->Render();
- par8->Render();
- par9->Render();
- par10->Render();
- par11->Render();
- par12->Render();
- par13->Render();
- par14->Render();
- par15->Render();
- par16->Render();
- par17->Render();
- par18->Render();
- }
- }
- }
- if(!rendspeed)
- {
- rendspeed=15;
- if(number==1)
- {
- number=2;
- }
- else if(number==2)
- {
- number=3;
- }
- else if(number==3)
- {
- number=4;
- }
- else if(number==4)
- {
- number=1;
- }
- }
- if(JumpOrParticle==1)
- {
- logo->SetPosition(logoX,300);
- logo->Render();
- par3->Render();
- par4->Render();
- par5->Render();
- }
- }
- };
- #endif