Timer C++

closed account (iNU7ko23)
Hi so currently I'm making a simple game. But I need there to be a timer so that after 30 seconds it says how many points you've achieved. I'm pretty shore a header will contain this, but what header is it? so what header would I need?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void GameCycle()
{
  // Update the saucer position

  g_iSaucerX = min(500 - g_pSaucer->GetWidth(), max(0, g_iSaucerX + g_iSpeedX));
  g_iSaucerY = min(360, max(0, g_iSaucerY + g_iSpeedY));
  if( (g_iSaucerX  >  (g_civilianX - 1.5)) &&    (g_iSaucerX  < (g_civilianX + 1.5)) ||  (g_iSaucerY  >  (g_civilianY - 1.5)) &&    (g_iSaucerY  < (g_civilianY + 1.5)))

  {
	  g_civilianX = rand() % 499;
	  g_civilianY = rand() % 359;
	  count++;
  }

  // Force a repaint to redraw the saucer
  InvalidateRect(g_pGame->GetWindow(), NULL, FALSE);
}
You can use GetTickCount which returns the milliseconds since the system was started. Call it twice, compare the results. When the difference is 30 seconds - do next GameCycle()

If you're using WINAPI u can use the WM_TIMER msg called with SetTimer
You should simply use clock() form the "cmath" header.
Topic archived. No new replies allowed.