예제 #1
0
파일: Main.cpp 프로젝트: 88er/tutorials
int main()
{
	// Initialize our data
	Init();

	// Below we do our basic game loop.  This is what control the game primarily.
	// We only want the game to keep going as long as the character is alive.  Of
	// course, in this tutorial the character can't die, but we set this up for later.
	// In the game loop we always check for input every frame, then we draw the map.
	// We don't draw the map every frame, but inside the Draw() function there is
	// a check to see if the draw flag is set.  That is why we use the SetDrawFlag()
	// function to tell the map to draw.  If we don't set that each frame, the map
	// will not draw, even though we call the Draw() flag.  

	// Keep the game going while the player is alive
	while(g_Player.IsAlive())
	{
		// If the user did some input, let's check it and handle it
		if(g_Input.CheckInput())
			HandleGameInput();

		// Let's draw the map when we need to draw (if the draw flag = true).
		g_Map.Draw();
	}

	// Return a success with no problems
	return 1;
}
예제 #2
0
WPARAM MainLoop()
{
	MSG msg;
	// This is where we load our accelerators for keyboard shortcuts
	HACCEL hAccelTable = LoadAccelerators(g_hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR1));

	while(g_Player.IsAlive())							// Loop until the player is dead
	{													// Check if there was a message
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
        { 
			if(msg.message == WM_QUIT)					// If the message was to quit
				break;

			// Check if there was keyboard command - if not, process messages like normal
			if(!TranslateAccelerator(g_hWnd, hAccelTable, &msg))
			{
				TranslateMessage(&msg);					// Find out what the message does
				DispatchMessage(&msg);					// Execute the message
			}

			// Here is where we handle the main game input
			HandleGameInput();

			// Let's draw the map when we need to draw (if the draw flag == true).
			g_Map.Draw();

			// Just like the g_Map.Draw() command, we will attempt to draw the menu, but it
			// will only be draw if it's draw flag is set to true.  This is the main menu.
			g_Menu.Draw();

			// Swap the backbuffers to display the bitmaps to the screen
			g_Buffer.SwapBackBuffer(FALSE);
		} 

		// We want the Npcs to freely walk around so we need to move them every frame
		g_Map.MoveNpcs();

		// Move the monsters randomly around the map  
		g_Map.MoveMonsters();
	}

	// If the player died because they were killed, let's display a death sound
	if(!g_Player.IsAlive())
	{
		// We use PlaySound() to play our .wav files
		PlaySound("Death.wav", NULL, SND_FILENAME | SND_ASYNC);
		g_Menu.DrawMessageBox("You have perished!");
		Sleep(1000);
	}

	// Clean up and free all allocated memory
	DeInit();											

	// Return from the program
	return(msg.wParam);									
}
예제 #3
0
void LoadOrSaveAMap(bool bLoad)
{
    string strMapName = "";		// Create a STL string to read in the input from the user
    char szName[255] = {0};		// Create a traditional string of characters for the file name

    // In this function we setup a prompt for the user to type in the file name to
    // either save or load.  If you want to load a file, you pass in "true", otherwise
    // we use "false" to indicate that we want to save a file.  This cuts down on code
    // since a lot of the code is the same for each action.  This function doesn't
    // actually do the saving and loading code, but handles the input from the user.
    // The save and load code is in our CMap::Load() and CMap::Save() functions that
    // we call from here.

    // Get an output handle for the console window and set the cursor position for a prompt
    HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(hOutput, g_promptPos);

    // To clear the prompt, we just print out a bunch of tabs and then reset the cursor position
    cout << "\t\t\t\t\t\t\t\t\t\t";
    SetConsoleCursorPosition(hOutput, g_promptPos);

    // Get an input handle and set the console window to allow input from the user
    // and echo it to the screen.  This is important.  If you don't set this mode,
    // the user won't see what they are typing.
    HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
    SetConsoleMode(hInput, ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT);

    // Below we check if we want to load or save a file, then display the appropriate message
    if(bLoad)
        cout << "Enter a map to Load: ";
    else
        cout << "Enter a map to Save: ";

    // Here we get the map name that we want to save or load
    cin >> strMapName;

    // Then we extract the string from the string class and put it in a normal array or characters
    strcpy(szName, strMapName.c_str());

    // Next we either load or save the map entered by the user, depending on bLoad
    if(bLoad)
        g_Map.Load(szName);
    else
        g_Map.Save(szName);

    // Next, we restore the console mode for getting mouse and keyboard input and redraw the screen
    SetConsoleMode(hInput, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT);
    g_Map.Draw();
}
예제 #4
0
파일: Main.cpp 프로젝트: 88er/tutorials
int main()
{
	// Initialize our data
	Init();

	// Draw the map to the screen
	g_Map.Draw();

	// Do an infinite loop until we exit the program by ESC or Control-C
	while(1)
	{
		// If we used the mouse or the keyboard, let's draw the map again
		if(CheckInput())
		{
			// Draw our current map that is open
			g_pCurrentMap->Draw();
		}
	}
	
	// Return a success with no problems
	return 1;
}
예제 #5
0
파일: Main.cpp 프로젝트: 88er/tutorials
void LoadOrSaveAMap(bool bLoad)
{
	string strMapName = "";		// Create a STL string to read in the input from the user
	char szName[255] = {0};		// Create a traditional string of characters for the file name

	// Get an output handle for the console window and set the cursor position for a prompt
	HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hOutput, g_promptPos);

	// To clear the prompt, we just print out a bunch of tabs and then reset the cursor position
	cout << "\t\t\t\t\t\t\t\t\t\t";
	SetConsoleCursorPosition(hOutput, g_promptPos);

	// Get an input handle and set the console window to allow input from the user 
	HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);			
	SetConsoleMode(hInput, ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT);

	// Below we check if we want to load or save a file, then display the appropriate message
	if(bLoad)
		cout << "Enter a map to Load: ";
	else
		cout << "Enter a map to Save: ";

	// Here we get the map name that we want to save or load
	cin >> strMapName;

	// Then we extract the string from the string class and put it in a normal array or characters
	strcpy(szName, strMapName.c_str());

	// Next we either load or save the map entered by the user, depending on bLoad
	if(bLoad)
		g_Map.Load(szName);
	else
		g_Map.Save(szName);

	// Next, we restore the console mode for getting mouse and keyboard input and redraw the screen
	SetConsoleMode(hInput, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT);
	g_Map.Draw();	
}
예제 #6
0
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// Draw
///////////////////////////////////////////////////////////////////////////////////////////////////////////
void Draw()
{
	BYTE *bypDest = g_cScreenDib.GetDibBuffer();
	int iDestWidth = g_cScreenDib.GetWidth();
	int iDestHeight = g_cScreenDib.GetHeight();
	int iDestPitch = g_cScreenDib.GetPitch();	

	g_cTileMap.Draw(g_pSpriteDib, bypDest, iDestWidth, iDestHeight, iDestPitch);

	///////////////////////////////////////////////////////////////////////////////////////////////////////
	// Y축 정렬
	///////////////////////////////////////////////////////////////////////////////////////////////////////
	g_Object.sort(GreaterY());


	///////////////////////////////////////////////////////////////////////////////////////////////////////
	// Effect, Player 정렬
	///////////////////////////////////////////////////////////////////////////////////////////////////////
	g_Object.sort(EffectOrPlayer());

	Object::iterator oIter;
	for (oIter = g_Object.begin(); oIter != g_Object.end(); ++oIter)
		(*oIter)->Draw(g_pSpriteDib, bypDest, iDestWidth, iDestHeight, iDestPitch);
}
예제 #7
0
파일: main.cpp 프로젝트: houapple/raindrop
void CGameApp::Draw(float elapsed_time)
{
	m_Map.Draw(elapsed_time);
}
예제 #8
0
파일: astar.cpp 프로젝트: houapple/raindrop
void CGameApp::Draw(float fElapsedTime)
{
    m_Map.Draw(fElapsedTime);
}