📄 gameapp.cpp
字号:
//-------------------------------------------------------------------------------------
//
// 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.
//
//-------------------------------------------------------------------------------------
#include <stdio.h>
#include "GameApp.h"
#include "GameState.h"
#include "MeshEffect.hpp"
#include "GameStateLogo.hpp"
#include "GameStateSplash.hpp"
#include "GameStateLoading.hpp"
#include "GameStatePlay.hpp"
#include "GameStateOver.hpp"
GameApp::GameApp(JGE *engine): JApp(engine)
{
for (int i=GAME_STATE_LOGO;i<=GAME_STATE_OVER;i++)
mGameStates[i] = NULL;
}
GameApp::~GameApp()
{
}
void GameApp::Create()
{
mGameStates[GAME_STATE_LOGO] = new GameStateLogo(this);
mGameStates[GAME_STATE_LOGO]->Create();
mGameStates[GAME_STATE_SPLASH] = new GameStateSplash(this);
mGameStates[GAME_STATE_SPLASH]->Create();
mGameStates[GAME_STATE_LOADING] = new GameStateLoading(this);
mGameStates[GAME_STATE_PLAY] = new GameStatePlay(this);
mGameStates[GAME_STATE_OVER] = new GameStateOver(this);
mGameStates[GAME_STATE_OVER]->Create();
mCurrentState = NULL;
mNextState = mGameStates[GAME_STATE_LOGO];
}
void GameApp::LoadGameStates()
{
mGameStates[GAME_STATE_PLAY]->Create();
}
void GameApp::Destroy()
{
for (int i=GAME_STATE_SPLASH;i<GAME_STATE_PLAY;i++)
{
if (mGameStates[i])
{
mGameStates[i]->Destroy();
delete mGameStates[i];
}
}
}
void GameApp::Clear()
{
for (int i=GAME_STATE_SPLASH;i< GAME_STATE_PLAY;i++)
{
if (mGameStates[i])
{
mGameStates[i]->Destroy();
mGameStates[i] = NULL;
}
}
}
void GameApp::Update()
{
if (mEngine->GetButtonClick(PSP_CTRL_TRIANGLE)) // do a screen shot when TRIANGLE is pressed
{
char s[80];
sprintf(s, "ms0:/screenshot.png");
mEngine->ScreenShot(s);
}
// if (mEngine->GetButtonClick(PSP_CTRL_CROSS)) // exit when the CROSS is pressed
// {
// mEngine->End();
// return;
// }
if (mCurrentState != NULL)
mCurrentState->Update();
if (mNextState != NULL)
{
if (mCurrentState != NULL)
mCurrentState->End();
mCurrentState = mNextState;
mCurrentState->Start();
mNextState = NULL;
}
}
void GameApp::Render()
{
if (mCurrentState != NULL)
{
mCurrentState->Render();
}
}
void GameApp::SetNextState(int state)
{
mNextState = mGameStates[state];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -