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); }
void RenderScene() { // Make sure we have a current map pointer before we go shootin' blanks if(!g_pCurrentMap) return; // Here we set the portion of our bitmaps that we want to draw. RECT rPortion = {0, 0, TILE_WIDTH, TILE_HEIGHT}; // Next we draw the current map (Default is just all green grass tiles) g_pCurrentMap->Draw(); // Grab the size of the current tool bar type list (Not our map's placed tile lists) int size = g_pCurrentMap->GetCurrentTypeSize(); // Go through our tiles in the tool bar and draw them, but subtract the scroll bar position // from the size. This makes it so we only draw the tiles that can be seen in the tool bar. for(int i = 0; i < size - g_scrollBarPosY; i++) { // Depending on "i" and the scroll bar position, get the current tile's bitmap to draw HBITMAP bitmap = g_pCurrentMap->GetCurrentTypeTile(i + g_scrollBarPosY)->GetBitmap(); // If the tool bar is showing map tiles then draw the tiles with no transparency if(g_pCurrentMap->GetCurrentType() == TILE_TYPE) g_ToolBuffer.DisplayBitmap(bitmap, 0, TILE_WIDTH * i, rPortion); else // Draw the current tiles with a transparency (white) (i.e. items, monsters, etc...) g_ToolBuffer.DisplayTransparentBitmap(bitmap, 0, TILE_WIDTH * i, rPortion); } //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// DrawCursorTile(); // Draw the current cursor tile if chosen //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Swap the backbuffers to display the bitmaps to the screen g_Buffer.SwapBackBuffer(FALSE); g_ToolBuffer.SwapBackBuffer(TRUE); }