-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (43 loc) · 1.32 KB
/
main.cpp
File metadata and controls
61 lines (43 loc) · 1.32 KB
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
51
52
53
54
55
56
57
58
#include <iostream>
#include "SDL.h"
#include "Game.h"
const int TARGET_FPS = 60;
const int DELAY_TIME = 1000 / TARGET_FPS;
int main() {
// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cout << "SDL could not be initialized!" << std::endl
<< "SDL_Error: " << SDL_GetError() << std::endl;
return 1;
}
// Initialize SDL_ttf
if (TTF_Init() == -1) {
std::cerr << "TTF_Init() failed: " << TTF_GetError() << std::endl;
// Handle initialization failure
return 1;
}
Game game;
int initGaame = game.initialize();
if(initGaame != 0){
std::cout << "Game could not be initialized!" << std::endl;
return 1;
}
SDL_Event e; // Create an SDL event to handle events
while(game.isRunning){
Uint32 frameStart = SDL_GetTicks();
while (SDL_PollEvent(&e) != 0) {
if (e.type == SDL_QUIT) {
game.isRunning = false; // Exit the loop if the window is closed
}
game.handleEvents(e); // Handle player input
}
game.update();
game.render();
Uint32 frameTime = SDL_GetTicks() - frameStart;
if (frameTime < DELAY_TIME) {
SDL_Delay(DELAY_TIME - frameTime);
}
}
game.cleanup();
SDL_Quit();
}