-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.cpp
44 lines (35 loc) · 891 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
34
35
36
37
38
39
40
41
42
43
44
//Game is now divided into modules
#include "Game.h"
#include <iostream>
//Adding FPS
const int FPS = 60;
const int DELAY_TIME = 1000 / FPS; //originally it was 1000.0f
int main(int argc, char* argv[])
{
Uint32 frameStart, frameTime;
std::cout << "game init attempt...\n";
if (TheGame::Instance()->init("Chapter 1", 100, 100, 640, 480, false))
{
std::cout << "game init success!\n";
while (TheGame::Instance()->running())
{
frameStart = SDL_GetTicks();
TheGame::Instance()->handleEvents();
TheGame::Instance()->update();
TheGame::Instance()->render();
frameTime = SDL_GetTicks() - frameStart;
if (frameTime < DELAY_TIME)
{
SDL_Delay((int)(DELAY_TIME - frameTime));
}
}
}
else
{
std::cout << "game init failure - " << SDL_GetError() << "\n";
return -1;
}
std::cout << "game closing...\n";
TheGame::Instance()->clean();
return 0;
}