void Game::Shutdown(void) { // Shutdown DirectX. DestroyGraphics(); }
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR commandLine, int showCommand) { WNDCLASS wndClass = {0}; MSG msg; /* Register window class */ wndClass.hInstance = instance; wndClass.hbrBackground = CreateSolidBrush(RGB(0, 0, 0)); wndClass.lpszClassName = ClassName; wndClass.lpfnWndProc = WndProc; if (!RegisterClass(&wndClass)) exit(1); /* Create window */ g_hwnd = CreateWindow(ClassName, Title, WS_POPUP, 0, 0, 160 * ViewScale, 100 * ViewScale, 0, 0, instance, 0); if (!g_hwnd) exit(2); ShowWindow(g_hwnd, showCommand); UpdateWindow(g_hwnd); /* Initialize Graphics */ InitializeGraphics(g_hwnd); InitializeGame(); for (;;) { if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } else { TickGame(); Present(); } } DestroyGraphics(); return 0; }
void Game::Render(void) { pRT->BeginDraw(); pRT->Clear(D2DColor(CornflowerBlue)); switch (currState) { case Playing: { // Rendering Floor Textures pRT->DrawBitmap(floor1, floor1pos); pRT->DrawBitmap(floor2, floor2pos); pRT->DrawBitmap(floor3, floor3pos); // Render Black Ninja D2D1_RECT_F sourceRect; sourceRect.top = 0; sourceRect.bottom = 74; sourceRect.left = 88.0f * black.frame + 10; sourceRect.right = sourceRect.left + 74; pRT->DrawBitmap(black.sprite, black.position, 1.0F, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, sourceRect); // Render Grey Ninja sourceRect.left = 88.0f * grey.frame + 10; sourceRect.right = sourceRect.left + 74; pRT->DrawBitmap(grey.sprite, grey.position, 1.0F, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, sourceRect); // Render Rect pBrush->SetColor(D2DColor(Black)); iter = rects.begin(); for (size_t i = 0; iter != rects.end(); iter++) { pRT->FillRectangle(*iter, pBrush); } pBrush->SetColor(D2DColor(Yellow)); obstIter = obstacles.begin(); // Render Obstacles for (; obstIter != obstacles.end(); obstIter++) { pRT->FillRectangle(obstIter->position, pBrush); } // Rendering health bar blackhealth = D2D1::RectF(healthbar2.left, healthbar2.top, healthbar2.left + 4 * black.health, healthbar2.bottom); greyhealth = D2D1::RectF(healthbar1.left, healthbar1.top, healthbar1.left + 4 * grey.health, healthbar1.bottom); pBrush->SetColor(D2DColor(Red)); pRT->FillRectangle(blackhealth, pBrush); pRT->FillRectangle(greyhealth, pBrush); pBrush->SetColor(D2DColor(Yellow)); pRT->DrawRectangle(healthbar1, pBrush); pRT->DrawRectangle(healthbar2, pBrush); break; } case Menu: { pRT->DrawBitmap(menupanel, D2D1::RectF(700, 300, 1100, 900)); break; } } HRESULT hr = pRT->EndDraw(); if (hr == D2DERR_RECREATE_TARGET) { DestroyGraphics(); CreateGraphics(hWnd); } }