Ejemplo n.º 1
0
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
{
	g_hInstance = hInstance;	// Store application handle
	g_bWindowed = true;			// Windowed mode or full-screen

	// Init the window
	InitWindow();

	// Use this msg structure to catch window messages
	MSG msg; 
	ZeroMemory(&msg, sizeof(msg));
	//perform the count for frames per second
	_int64 cntsPerSec = 0;
	QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec);//perform function QueryPerformanceFrequency: returns a BOOL value; true if timer exist
	float secsPerCnt = 1.0f / (float)cntsPerSec; //typecast the long int into a float
	//create an int for prev time
	_int64 prevTimeStamp = 0;
	QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);

	//*************************************************************************
	// Initialize DirectX/Game here (call the Init method of your framwork)
	DXObj.Init(g_hWnd, g_hInstance, g_bWindowed);
	MenuObj.Init(g_hWnd, g_hInstance, g_bWindowed);
	//*************************************************************************

	// Main Windows/Game Loop
	while(msg.message != WM_QUIT)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		//begin current time stamp counter
		_int64 currTimeStamp = 0;
		//receive counter performance
		QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp);
		float dt = (currTimeStamp - prevTimeStamp)*secsPerCnt;
		if(MenuObj.GetState() == 0) // Intro movie
		{
				DXObj.Update(dt);
				if(DXObj.GetMovieState() == true)
				{
					MenuObj.SetState(1);
				}
		}
		if(MenuObj.GetState() == 1)
		{
				//menu
				MenuObj.Update();
				MenuObj.Draw();
		}
		if(MenuObj.GetState() == 2)
		{
				//options
			MenuObj.Update();
			MenuObj.Draw();
		}
		if(MenuObj.GetState() == 3)
		{
				//game
			if(!g_bIsEnabled)
			{
				PFObj.Init(g_hWnd, g_hInstance, g_bWindowed);
				g_bIsEnabled = true;
			}
				PFObj.Update(dt);
				PFObj.Draw();
				if(PFObj.GetMenuBool())
				{
					MenuObj.SetState(1);
				}
		}
		if(MenuObj.GetState() == 4)
		{
				//credits
			MenuObj.Update();
			MenuObj.Draw();
		}
		if(MenuObj.GetState() == 5)
		{
				//quit game
				DXObj.Shutdown();
				PostQuitMessage(0);
		}
		//*************************************************************************
		// This is where you call your DirectXFramework/Game render/update calls
		
		//MenuObj.Draw();
		//PSObj.Draw();
		//*************************************************************************
		//Prepare for the next iteration: The current time
		//stamp becomes the previous time stamp for the next iteration
		
		prevTimeStamp = currTimeStamp; 

	}

	//*************************************************************************
	//Shutdown DirectXFramework/Game here
	DXObj.Shutdown();

	//*************************************************************************

	// Unregister window
	UnregisterClass(WINDOW_TITLE, g_hInstance);

	// Return successful
	return 0;
}