📄 cgame.cpp
字号:
#include "CGame.h"
//=========================================================================
// Name:CGame
// Desc: Constructors
//
//=========================================================================
CGame::CGame()
{
m_hgeEngine = NULL;
m_resource = NULL;
m_splash = NULL;
m_gameArea = NULL;
m_GameState = GAME_STATE_SPLASH;
}
//=========================================================================
// Name:Init
// Desc: Init the main game
//
//=========================================================================
bool CGame::Init( bool (*frameFunc)() )// Init the HGE enginer
{
srand(time(NULL));
m_hgeEngine = hgeCreate( HGE_VERSION );
if( m_hgeEngine == NULL )
return false;
m_hgeEngine->System_SetState(HGE_FRAMEFUNC, frameFunc);
m_hgeEngine->System_SetState(HGE_TITLE, "BrickShooter Jr (FULL ver)");
m_hgeEngine->System_SetState(HGE_WINDOWED, true );
m_hgeEngine->System_SetState(HGE_SHOWSPLASH, false);
m_hgeEngine->System_SetState(HGE_SCREENWIDTH, 800);
m_hgeEngine->System_SetState(HGE_SCREENHEIGHT, 600);
m_hgeEngine->System_SetState(HGE_SCREENBPP, 32);
m_hgeEngine->System_SetState( HGE_ICON, MAKEINTRESOURCE( IDI_ICON1 ) );
if( !m_hgeEngine->System_Initiate() )
{
return false;
}
m_resource = new CResource( m_hgeEngine );//creat resource
if( !m_resource->Init() )
{
return false;
}
m_splash = new CSplash( m_hgeEngine , m_resource->GetResMgr() );//create splash
if( !m_splash->Init() )
{
return false;
}
m_gameArea = new CGameArea( m_hgeEngine , m_resource->GetResMgr() );//create the main game
if( !m_gameArea->Init() )
{
return false;
}
return true;
}
//=========================================================================
// Name:Release
// Desc:when the whole game exit ,call this function
//
//=========================================================================
void CGame::Release()
{
if( m_resource != NULL )
m_resource->Release();
SAFE_DELETE( m_resource );
//Here need to delete the CScene which you are in now
m_hgeEngine->System_Shutdown();
m_hgeEngine->Release();
}
//=========================================================================
// Name:Start
// Desc: start the engine
//
//=========================================================================
bool CGame::Start()
{
m_GameState = GAME_STATE_SPLASH;
return m_hgeEngine->System_Start();
}
//=========================================================================
// Name:GameMain
// Desc:the main loop of the game
//
//=========================================================================
bool CGame::MainLoop()
{
switch( m_GameState )
{
case GAME_STATE_SPLASH:
if( GameSplash() )
{
return false;
}
break;
case GAME_STATE_PLAY:
if( GamePlay() )
{
return true;
}
break;
}
return false;
}
//=========================================================================
// Name:GameSplash
// Desc:the loop of the first Splash
//
//=========================================================================
bool CGame::GameSplash()
{
if( m_splash == NULL )
return true;
if( m_splash->Update() )
{
m_splash->Release();
m_GameState = GAME_STATE_PLAY;
return true;
}
m_splash->Render();
return false;
}
//=========================================================================
// Name:GamePlay
// Desc:the loop of the main game
//
//=========================================================================
bool CGame::GamePlay()
{
if( m_gameArea == NULL )
return true;
m_MainGameResult m_result = m_gameArea->Update();
switch( m_result )
{
case GAME_NOTHING:
m_gameArea->Render();
return false;
case GAME_OVER:
return true;
}
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -