www.pudn.com > GameEngine_src.rar > WndMsg.cpp


#include "WndMsg.h" 
#include "BaseUtil.h" 
#include "CAppWnd.h" 
#include "CDInput.h" 
#include "CTimer.h" 
#include "CEasyDraw.h" 
#include "CEasyAudio.h" 
#include "CHero.h" 
#include "CMap.h" 
#include "CMessageManager.h" 
#include "CGameManager.h" 
#include "CResourceManager.h" 
#include "CPathSeeker.h" 
#include "CSpriteFactory.h" 
#include "CNpcDlg.h" 
#include "CES_Executor.h" 
#include "CItemFactory.h" 
#include "CMagicFactory.h" 
 
#include  
#include  
#include  
#include  
 
 
extern bool					g_IsActive; 
extern CAppWnd				theAppWnd;						//窗口 
extern PEASYDRAW			g_pEasyDraw; 
extern PEASYAUDIO			g_pEasyAudio; 
extern CTimer				theTimer; 
extern CDIKeyBoard			theKeyBoard; 
extern CDIMouse				theMouse; 
extern CHero				theHero; 
extern CMap					theMap; 
extern CMessageManager		theMsgMgr; 
extern CGameManager			theGameManager; 
extern CPathSeeker			thePathSeeker;			 
extern CSpriteFactory		theSpriteFactory; 
extern CNpcDlgMgr			theNpcDlgMgr; 
extern CES_Executor			theES_Executor; 
extern CItemFactory			theItemFactory; 
extern CMagicFactory		theMagicFactory; 
 
 
PSURFACE surf1; 
 
struct USER_SET 
{ 
	int		screenWidth; 
	int		screenHeight; 
	bool	bWindowed; 
	int		soundVolume; 
	int		musicVolume; 
}; 
 
/////////////////////////////////////////////////////////// 
//初始化图形层: 
/////////////////////////////////////////////////////////// 
bool InitGraphics( HWND hwnd ) 
{ 
	USER_SET userSet; 
	FILE *fp = fopen( "..\\data\\userSet.ini", "rb" ); 
	if ( fp != NULL ) 
	{ 
		fread( &userSet, sizeof(USER_SET), 1, fp ); 
		fclose(fp); 
	} 
	else 
	{ 
		userSet.screenWidth = 800; 
		userSet.screenHeight= 600; 
		userSet.bWindowed	= false; 
		userSet.soundVolume	= -4000; 
		userSet.musicVolume	= -4000; 
	} 
 
	g_pEasyAudio = InitEasyAudio( hwnd ); 
	if ( g_pEasyAudio == NULL ) 
		return false; 
 
	g_pEasyAudio->ChangeSoundVolume( userSet.soundVolume ); 
	g_pEasyAudio->ChangeMusicVolume( userSet.musicVolume ); 
 
	g_pEasyDraw = InitEasyDraw( hwnd, userSet.bWindowed, userSet.screenWidth, userSet.screenHeight ); 
	if ( g_pEasyDraw == NULL ) 
		return false; 
 
	if ( theKeyBoard.Init( hwnd, theAppWnd.GetHInstance() ) == false ) 
		return false; 
 
	if ( theMouse.Init( hwnd, theAppWnd.GetHInstance() ) == false ) 
		return false; 
 
	surf1 = g_pEasyDraw->CreateSurfaceEx( NULL, 64, 24, true, true, 0x00 ); 
	if ( surf1 == 0 ) 
		return false; 
 
	if ( theMap.Init() == false ) 
		return false; 
 
	if ( theHero.Init() == false ) 
		return false; 
 
	if ( theMsgMgr.Init() == false ) 
		return false; 
 
	if ( thePathSeeker.Init() == false ) 
		return false; 
 
	if ( theGameManager.Init() == false ) 
		return false; 
 
	if ( theSpriteFactory.Init() == false ) 
		return false; 
 
	if ( theNpcDlgMgr.Init() == false ) 
		return false; 
 
	if ( theItemFactory.Init() == false ) 
		return false; 
 
	if ( theES_Executor.Init() == false ) 
		return false; 
 
	if ( theMagicFactory.Init() == false ) 
		return false; 
 
	return true; 
} 
 
 
/////////////////////////////////////////////////////////// 
//程序结束工作 
/////////////////////////////////////////////////////////// 
void OnQuit() 
{ 
	theHero.Free(); 
	theES_Executor.Free(); 
	theItemFactory.Free(); 
	theMagicFactory.Free(); 
	theNpcDlgMgr.Free(); 
	theSpriteFactory.Free(); 
	theGameManager.Free(); 
	theMsgMgr.Free(); 
	theMap.Free(); 
	thePathSeeker.Free(); 
 
	theKeyBoard.Free(); 
	theMouse.Free(); 
	FreeEasyDraw(); 
	FreeEasyAudio(); 
	PostQuitMessage( NULL ); 
} 
 
 
 
/////////////////////////////////////////////////////////// 
// 
/////////////////////////////////////////////////////////// 
void OnMouseWheel( WPARAM wParam ) 
{ 
 
} 
 
 
/////////////////////////////////////////////////////////// 
// 
/////////////////////////////////////////////////////////// 
void OnWndMove( HWND hwnd, WPARAM wParam, LPARAM lParam ) 
{ 
	if ( g_pEasyDraw != NULL ) 
		g_pEasyDraw->UpdateRect();		 
} 
 
/////////////////////////////////////////////////////////// 
// 
/////////////////////////////////////////////////////////// 
void OnSize( HWND hwnd, WPARAM wParam, LPARAM lParam ) 
{ 
 
} 
 
 
/////////////////////////////////////////////////////////// 
// 
/////////////////////////////////////////////////////////// 
void Render( ) 
{	 
	theMouse.UpdateMouse(theAppWnd.GetHWnd()); 
	theKeyBoard.UpdateKeyBoard(); 
	g_pEasyAudio->UpdateMP3(); 
 
	theGameManager.OnGameLoop(); 
	theTimer.UpdateFps(); 
 
	char sz[8]; 
	wsprintf( sz, "%d", theTimer.GetFps() ); 
 
	surf1->ClearSurface( 0x0, NULL ); 
	surf1->WriteText( sz, strlen(sz), 0, 0, 0xffffff ); 
	surf1->DrawSurface( 0, 0, NULL ); 
 
	g_pEasyDraw->Present(); 
} 
 
 
void ActiveWnd() 
{ 
	g_IsActive = true; 
	theMouse.OnActive(); 
	theKeyBoard.OnActive(); 
} 
 
void InactiveWnd() 
{ 
	g_IsActive = false; 
	theMouse.OnInactive(); 
	theKeyBoard.OnInactive(); 
	SetWindowText( theAppWnd.GetHWnd(), "inactive" ); 
}