forked from Cowa/Swrid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (56 loc) · 1.74 KB
/
main.cpp
File metadata and controls
66 lines (56 loc) · 1.74 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
59
60
61
62
63
64
65
66
#include "include/Define.h"
#include "include/Engine.h"
using namespace std;
int main(void)
{
// On rend l'aléatoire aléatoire
srand(time(0));
/***************************
* Variables liées à la SDL *
***************************/
SDL_Surface *screen; // surface principale
SDL_Event event;
FPSmanager frame_manager;
bool loop = true; // variable pour la boucle globale
/***************************
* Initialisation de la SDL *
***************************/
if(SDL_Init(SDL_INIT_VIDEO) == -1)
{
cout << "SDL Init error" << endl;
exit(EXIT_FAILURE);
}
if((screen = SDL_SetVideoMode(800, 600, 32, SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_RESIZABLE)) == NULL)
{
cout << "SDL Video set error" << endl;
exit(EXIT_FAILURE);
}
SDL_WM_SetCaption("Prototype", NULL); // Nom de la fenêtre
SDL_initFramerate(&frame_manager);
SDL_setFramerate(&frame_manager, FPS); // on fixe le fps à 60
/*********************
* Création du moteur *
*********************/
Engine engine(screen, &event, &loop); // on crée le moteur
engine.init(); // on initialise
// On nettoie la grille
while(engine.getGrid()->purge())
{
engine.getGrid()->update_gravity();
}
/******************
* Boucle générale *
******************/
while(loop)
{
engine.event(); // on gère les événements
engine.render(); // on prépare l'affichage de l'UI
SDL_Flip(screen); // on affiche l'écran
SDL_framerateDelay(&frame_manager); // régulateur de frames
}
/***************************
* Libération de la mémoire *
***************************/
SDL_Quit();
return EXIT_SUCCESS;
}