-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameover.cpp
executable file
·118 lines (99 loc) · 3.26 KB
/
gameover.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "gameover.h"
GameOver::GameOver(Moteur * _p)
{
TTF_Init();
if (TTF_Init() == -1)
{
fprintf(stderr, "Erreur d'initialisation de TTF_Init : %s\n", TTF_GetError());
exit(EXIT_FAILURE);
}
police = TTF_OpenFont("police/arial.ttf", 24);
SDL_Color couleurNoire = {0, 0, 0}, couleurBlanche = {255, 255, 255}, couleurGrise = {120, 120, 120};
sdl_game_o = TTF_RenderText_Shaded(police, "Game Over", couleurGrise, couleurNoire);
sdl_quitter = TTF_RenderText_Shaded(police, "Quitter", couleurBlanche, couleurNoire);
sdl_restart = TTF_RenderText_Shaded(police, "Recommencer", couleurBlanche, couleurNoire);
sdl_menu = SDL_LoadBMP("images/menu.bmp");
sdl_curseur = SDL_LoadBMP("images/curseur_menu.bmp");
positionCurseur = 0;
parent = _p;
}
GameOver::~GameOver()
{
parent = NULL;
SDL_FreeSurface(sdl_restart);
SDL_FreeSurface(sdl_quitter);
SDL_FreeSurface(sdl_menu);
SDL_FreeSurface(sdl_game_o);
SDL_FreeSurface(sdl_curseur);
TTF_CloseFont(police);
TTF_Quit();
}
void GameOver::affiche(SDL_Surface * screen)
{
SDL_Rect position, positionRel;
positionRel.w=20;
positionRel.h=15;
position.y = screen->h/2 - sdl_menu->h/2;
position.x = LARGEUR_FENETRE/2-(sdl_menu->w/2);
SDL_BlitSurface(sdl_menu, NULL, screen, &position);
position.y += 20;
position.x += 30;
SDL_BlitSurface(sdl_game_o, NULL, screen, &position);
position.y +=60;
position.x = LARGEUR_FENETRE/2-(sdl_restart->w/2);
SDL_BlitSurface(sdl_restart, NULL, screen, &position);
SDL_SetClipRect(sdl_restart,&position);
position.y +=30;
position.x = LARGEUR_FENETRE/2-(sdl_quitter->w/2);
SDL_BlitSurface(sdl_quitter, NULL, screen, &position);
SDL_SetClipRect(sdl_quitter,&position);
position.y = screen->h/2 - sdl_menu->h/2;
if (positionCurseur == 0)
{
position.y = sdl_restart->clip_rect.y+(sdl_curseur->h/2);
position.x = LARGEUR_FENETRE/2-(sdl_restart->w/2)-(sdl_curseur->w/2);
}
else if (positionCurseur == 1)
{
position.y = sdl_quitter->clip_rect.y+(sdl_curseur->h/2);
position.x = LARGEUR_FENETRE/2-(sdl_quitter->w/2)-(sdl_curseur->w/2);
}
positionRel.x=0;
positionRel.y=0;
SDL_BlitSurface(sdl_curseur, &positionRel, screen, &position);
if (positionCurseur == 0)
{
position.x += sdl_restart->w+sdl_curseur->w/2;
}
else if (positionCurseur == 1)
{
position.x += sdl_quitter->w+sdl_curseur->w/2;
}
positionRel.x=20;
SDL_BlitSurface(sdl_curseur, &positionRel, screen, &position);
}
void GameOver::gereTouche(int touche)
{
if (touche == SDLK_DOWN)
{
if (positionCurseur == 1)
positionCurseur = 0;
else
positionCurseur++;
}
else if (touche == SDLK_UP)
{
if (positionCurseur == 0)
positionCurseur = 1;
else
positionCurseur--;
}
else if (touche == SDLK_SPACE || touche == SDLK_RETURN)
{
if (positionCurseur == 0)
parent->restartJeu();
else if (positionCurseur == 1)
parent->setQuitter(true);
else;
}
}