void GameObject::Physics(const float ticks) { DoPhysics(ticks); GameObjectPtrList::iterator iter = m_children.begin(); for ( ; iter != m_children.end(); ++iter) { (*iter)->Physics(ticks); } }
void Particle::Update(float frametime) { DoPhysics(frametime); if (this->size > 2.0f) this->size -= 6 * frametime; else this->size -= 2 * frametime; if (this->color.Lightness > 0.66f) this->color.Lightness -= frametime; else this->color.Lightness -= 0.33 * frametime; }
void SpawnerParticle::Update(float frametime) { DoPhysics(frametime); if (lifetime > fuseTime && particles == NULL) { Explode(); } else if (particles != NULL) { if (particles->Count() < maxParticles && lifetime < (maxLifetime - 2.0f)) SpawnParticle(); particles->Update(frametime); } }
void CollisionApp::DoFrame(double a_dt) { double frameRate = 1.0 / 60.0; DoPhysics(frameRate); Render(); double remaining = frameRate - a_dt; if (remaining > 0.0) { int ms = int(remaining * 1000.0); std::this_thread::sleep_for(std::chrono::milliseconds(ms)); } }
/*! *Main function which performs the window-creation action and calls main processing function called doPhysics *@return hInstance, hPrevInstance, lpCmdLine, nCmdShow */ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wcex.lpszMenuName = NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); if (!RegisterClassEx(&wcex)) { MessageBox(NULL, _T("Call to RegisterClassEx failed!"), _T("Win32 Guided Tour"), NULL); return 1; } hInst = hInstance; // Store instance handle in our global variable // The parameters to CreateWindow explained: // szWindowClass: the name of the application // szTitle: the text that appears in the title bar // WS_OVERLAPPEDWINDOW: the type of window to create // CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y) // 500, 100: initial size (width, length) // NULL: the parent of this window // NULL: this application does not have a menu bar // hInstance: the first parameter from WinMain // NULL: not used in this application HWND hWnd = CreateWindow( szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL ); if (!hWnd) { MessageBox(NULL, _T("Call to CreateWindow failed!"), _T("Win32 Guided Tour"), NULL); return 1; } // The parameters to ShowWindow explained: // hWnd: the value returned from CreateWindow // nCmdShow: the fourth parameter from WinMain ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); MSG msg; ULONGLONG prevTime = -1, curTime, deltaT; StartGame(); // Enter the infinite message loop while (TRUE) { // Check to see if any messages are waiting in the queue while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // Translate the message and dispatch it to WindowProc() TranslateMessage(&msg); DispatchMessage(&msg); } // If the message is WM_QUIT, exit the while loop if (msg.message == WM_QUIT) break; curTime = GetTickCount64(); if (prevTime == -1) deltaT = 0; else deltaT = curTime - prevTime; prevTime = curTime; DoPhysics(deltaT); InvalidateRect(hWnd, NULL, 1); } return (int)msg.wParam; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); if (!RegisterClassEx(&wcex)) { MessageBox(NULL, _T("Call to RegisterClassEx failed!"), _T("Win32 Guided Tour"), NULL); return 1; } hInst = hInstance; // Store instance handle in our global variable /** @function CreateWindow @brief The function that creates the window. @param szWindowClass The class name @param szTitle Window Name @param WS_OVERLAPPEDWINDOW: the type of window to create @param CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y) @param 800/700 The width and height of the window @param NULL Handle to the parent window and menu handle @param hInstance Handle to application instance @param NULL Parameters transmitted from the WndProc */ HWND hWnd = CreateWindow( szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 700, NULL, NULL, hInstance, NULL ); if (!hWnd) { MessageBox(NULL, _T("Call to CreateWindow failed!"), _T("Win32 Guided Tour"), NULL); return 1; } /** @function ShowWindow @brief Function to display the window. @param hWnd Window Handle @param nCmdShow Window Display Mode */ ShowWindow(hWnd, nCmdShow); /** @function UpdateWindow @brief Function to update the window. @param hWnd Window Handle */ UpdateWindow(hWnd); /// The main message loop MSG msg; ULONGLONG prevTime = -1, curTime, deltaT; /// Call Start function StartGame(); /// Enter the infinite message loop while(TRUE) { /// Check to see if any messages are waiting in the queue while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { /// Translate the message and dispatch it to WindowProc() TranslateMessage(&msg); DispatchMessage(&msg); } /// If the message is WM_QUIT, exit the while loop if(msg.message == WM_QUIT) break; /// Removing the number of milliseconds that have elapsed since the system was launched curTime = GetTickCount64(); /// Determination of the time change if (prevTime == -1) deltaT = 0; else deltaT = curTime - prevTime; prevTime = curTime; /// Calling a function is responsible for the application physics if(!pause){ DoPhysics(deltaT); } /// Calling a function that initiates a redraw window InvalidateRect(hWnd,NULL,1); } return (int) msg.wParam; }