-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
42 lines (32 loc) · 1011 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
#ifdef __cplusplus
#include <cstdlib>
#else
#include <stdlib.h>
#endif
#include <string>
#include "Game.h"
//MAIN CONSTANTS
const int FPS = 60; ///////////////////_______________////
const int DELAY_TIME = 1000.0f / FPS;//fixed framerate////
using namespace std;
int main ( int argc, char** argv )
{
Uint32 frameStart, frameTime;
if(TheGame::Instance()->init("Chapter 1", 100, 100, 640, 480, 0))
{
while (TheGame::Instance()->running())
{
frameStart = SDL_GetTicks(); //fixed frame rate var
TheGame::Instance()->handleEvents();
TheGame::Instance()->update();
TheGame::Instance()->render();
frameTime = SDL_GetTicks() - frameStart; //fixed frame rate var
if (frameTime < DELAY_TIME) //fixed frame rate
{
SDL_Delay((int)(DELAY_TIME - frameTime)); //delay to achieve fixed frame rate
}
}
TheGame::Instance()->clean();
}
return 0;
}