-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (39 loc) · 979 Bytes
/
main.cpp
File metadata and controls
50 lines (39 loc) · 979 Bytes
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
45
46
47
48
49
50
/*
* Copyright (c) 2014 Ross Simpson
* All Right Reserved
*
* This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
* To view a copy of this license,visit http://creativecommons.org/licenses/by-nc-sa/4.0/.
*/
#include <string>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "gamestate.h"
using namespace std;
const uint32_t FPS = 60;
const uint32_t DELAY_TIME = 1000.0f / FPS;
int main()
{
if (GameState::get()->init("EndlessQuest"))
{
uint32_t frameStart, frameTime;
while (GameState::get()->isRunning())
{
frameStart = SDL_GetTicks();
GameState::get()->handleEvents();
GameState::get()->update();
GameState::get()->render();
frameTime = SDL_GetTicks() - frameStart;
if (frameTime < DELAY_TIME)
{
SDL_Delay((int)DELAY_TIME - frameTime);
}
}
}
else
{
cout << "Failed to initialize Game State" << endl;
}
GameState::get()->destroy();
return 0;
}