-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
33 lines (28 loc) · 851 Bytes
/
Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "stdafx.h"
#include "Game.h"
#include <chrono> // https://en.cppreference.com/w/cpp/chrono
#include <thread> // https://en.cppreference.com/w/cpp/thread
using namespace std::chrono;
float frameTimer = 1000.0f / FRAMES_PER_SECOND;
int main()
{
srand((int)time(0));
SetConsoleOutputCP(437); // use usa char set for drawing boxes
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
Game game;
while (true)
{
auto start = steady_clock::now();
if (game.Update() == false)
break;
game.Render();
if (GetAsyncKeyState(VK_UP) & 0x1)
frameTimer-=5;
if (GetAsyncKeyState(VK_DOWN) & 0x1)
frameTimer+=5;
auto end = steady_clock::now();
auto durationMS = duration_cast<milliseconds>(end - start);
auto timeLeft = frameTimer - durationMS.count();
std::this_thread::sleep_for(milliseconds(int(timeLeft)));
}
}