📄 gamestatesplash.hpp
字号:
//-------------------------------------------------------------------------------------
//
// This is part of MarioDemo, a platformer demo for JGE++
//
// Copyright (C) 2006 James Hui (a.k.a. Dr.Watson)
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option) any
// later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the Free Software Foundation, Inc., 59 Temple
// Place, Suite 330, Boston, MA 02111-1307 USA
//
// Bugs and comments can be forwarded to jhkhui@yahoo.com.
//
//-------------------------------------------------------------------------------------
#ifndef _GAME_STATES_SPLASH_H_
#define _GAME_STATES_SPLASH_H_
#include "GameState.h"
#define SPLASH_DELAY 4000.0f
#define SPLASH_DELAY_2 2000.0f
class MeshEffect;
class GameStateSplash: public GameState
{
private:
JTexture* mSplashTex;
//JTexture* mSplashTex_2;
JTexture* mTileTex;
JQuad* mSplashQuad;
int mStage;
float mAlpha;
float mTimer;
float mDelta;
float mMax;
float mMaxDelta;
float mBgX;
float mBgY;
float mYDelta;
MeshEffect* mEffect;
JQuad* mBg;
JQuad* mMario;
JQuad* mPrincess;
JQuad* mMonster;
JQuad* mMushroom;
JQuad* mStart;
JQuad* mTileMap;
JMusic* mMusic;
public:
GameStateSplash(GameApp* app): GameState(app)
{
mEffect = NULL;
mBg = NULL;
mSplashQuad = NULL;
mPrincess = NULL;
mMushroom = NULL;
mMonster = NULL;
mMario = NULL;
mStart = NULL;
mMusic = NULL;
}
virtual ~GameStateSplash()
{
}
virtual void Create()
{
mSplashTex = mEngine->LoadTexture("Res/splash_2.png", true);
//mSplashTex_2 = mEngine->LoadTexture("Res/splash.bmp", true);
mSplashQuad = new JQuad(mSplashTex, 0.0f, 0.0f, 332.0f, 180.0f);
mBg = new JQuad(mSplashTex, 337.0f, 106.0f, 60.0f, 147.0f);
mMushroom = new JQuad(mSplashTex, 406.0f, 210.0f, 32.0f, 32.0f);
mMario = new JQuad(mSplashTex, 406.0f, 106.0f, 66.0f, 88.0f);
mMonster = new JQuad(mSplashTex, 390.0f, 0.0f, 121.0f, 102.0f);
mPrincess = new JQuad(mSplashTex, 336.0f, 0.0f, 54.0f, 98.0f);
mStart = new JQuad(mSplashTex, 0.0f, 188.0f, 213.0f, 40.0f);
mEffect = new MeshEffect(mSplashTex, 0, 0, 332, 180);
mTileTex = mEngine->LoadTexture("Res/splash.bmp", true);
mTileMap = new JQuad(mTileTex, 0.0f, 0.0f, 640.0f, 480.0f);
mMusic = mEngine->LoadMusic("Res/smarioc.mod");
}
virtual void Destroy()
{
if (mSplashQuad)
delete mSplashQuad;
if (mSplashTex)
mEngine->FreeTexture(mSplashTex);
if (mEffect)
delete mEffect;
if (mBg) delete mBg;
if (mPrincess) delete mPrincess;
if (mMushroom) delete mMushroom;
if (mMonster) delete mMonster;
if (mMario) delete mMario;
if (mStart) delete mStart;
if (mMusic)
mEngine->FreeMusic(mMusic);
}
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(300.0f, 40.0f);
//mEffect->SetMode(MESH_EFFECT2);
mBgX = 0.0f;
mYDelta = -0.02f;
mBgY = 0.0f;
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_CROSS)) // skip everything...
{
if (mStage == 0)
{
mStage = 1;
mAlpha = 255.0f;
mEffect->SetMax(0.0f);
mEffect->SetAlpha(255.0f);
mEffect->Update(dt);
mEngine->PlayMusic(mMusic);
return;
}
}
if (mEngine->GetButtonClick(PSP_CTRL_START))
{
mApp->SetNextState(GAME_STATE_LOADING);
return;
}
if (mStage == 0)
{
mAlpha += mDelta*dt;
if (mAlpha > 255.0f)
{
mAlpha = 255.0f;
//mTimer = 0.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
{
//mBgX -= 0.05f*dt;
//if (mBgX < -768.0f)
// mBgX += 768.0f;
mBgY += mYDelta*dt;
if (mBgY < -4.0f)
{
mYDelta *= -1;
mBgY += mYDelta*dt;
}
else if (mBgY > 4.0f)
{
mYDelta *= -1;
mBgY += mYDelta*dt;
}
}
}
virtual void Render()
{
mEngine->ClearScreen(ARGB(255,255,255,255));
int alpha = (int) mAlpha;
mEngine->FillRect(0.0f, 0.0f, 640.0f, 480, ARGB(alpha, 0, 100, 255));
float x = (mStage == 0)?0.0f:mBgX;
float y = 0.0f;
for (int i=0;i<2;i++)
{
mBg->SetColor(ARGB(alpha, 255, 255, 255));
mEngine->RenderQuad(mTileMap, x, y);
x += 768.0f;
}
//if (mStage == 0)
{
mEffect->Render();
//return;
}
//mEngine->RenderQuad(mSplashQuad, 74.0f, 0.0f);
if (mStage == 1)
{
//mEngine->RenderQuad(mMario, 60, 110+mBgY);
mEngine->RenderQuad(mStart, 366, 208+mBgY);
//mEngine->RenderQuad(mPrincess, 120, 246);
//mEngine->RenderQuad(mMonster, 440, 246);
mEngine->RenderQuad(mMushroom, 330, 210);
mEngine->RenderQuad(mMushroom, 578, 210);
}
}
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -