-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·83 lines (72 loc) · 2.1 KB
/
main.cpp
File metadata and controls
executable file
·83 lines (72 loc) · 2.1 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <SDL/SDL_framerate.h>
#include "constantes.h"
#include "moteur.h"
int main ( int argc, char** argv )
{
//initialisation de la SDL
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
std::cerr << "Unable to init SDL:" << SDL_GetError() << std::endl;
return 1;
}
//Moteur du jeu
Moteur moteur;
if (!moteur.init())
{
std::cerr << "L'initialisation du moteur a échoué.";
return 1;
}
//declaration variables
bool avancement = false;
int tempsPrecedent = 0, tempsActuel = 0;
SDL_Surface* screen = SDL_SetVideoMode(LARGEUR_FENETRE+150, HAUTEUR_FENETRE, 16,SDL_HWSURFACE|SDL_DOUBLEBUF);
SDL_WM_SetCaption("Tetris", NULL);
FPSmanager manager;
SDL_initFramerate(&manager);
SDL_setFramerate(&manager,30);
SDL_Event event;
SDL_EnableKeyRepeat(10, 50);
//boucle principale tant que le jeu n'est pas fini
while (!moteur.getQuitter())
{
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
moteur.setQuitter(true);
break;
case SDL_KEYUP:
{
moteur.gereTouche(0);
break;
}
case SDL_KEYDOWN:
{
if (event.key.keysym.sym == SDLK_DOWN)
avancement = true;
//envoi la touche pressée à Moteur
moteur.gereTouche(event.key.keysym.sym);
break;
}
}
}
tempsActuel = SDL_GetTicks();
if (tempsActuel - tempsPrecedent > 600/moteur.getLvl())
{
avancement = true;
tempsPrecedent = tempsActuel;
}
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
if (avancement)
{
moteur.gereScene();
avancement = false;
}
//affiche
moteur.affiche(screen);
SDL_Flip(screen);
SDL_framerateDelay(&manager);
}
return 0;
}