-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameover.c
144 lines (120 loc) · 3.37 KB
/
gameover.c
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
void corte(SDL_Window *janela, SDL_Renderer *renderer);
void gravar_recorde(SDL_Window *janela, SDL_Renderer *renderer);
int continues = 0;
void condicao(int a)
{
continues = a;
}
void gameover(SDL_Window *janela, SDL_Renderer *renderer)
{
char acabou[] = "game over", sim[] = "sim (<---)", nao[] = "nao (--->)", denovo[] = "Quer continuar?";
texto1 = setElement( //texto1 = game over
"texto1",
TTF_RenderText_Solid(fonte, acabou, color),
createRect(0, 0, 9*48, 50),
createRect(WIDTH/12, 70, 10 * WIDTH/12, 0.20 * HEIGHT)
);
texto2 = setElement( //texto1 = quer continuar
"texto2",
TTF_RenderText_Solid(fonte1, denovo, color),
createRect(0, 0, 15*48, 50),
createRect(WIDTH/12, 400, 10 * WIDTH/12, 0.10 * HEIGHT)
);
texto3 = setElement( //texto1 = sim
"texto3",
TTF_RenderText_Solid(fonte1, sim, color),
createRect(0, 0, 10*48, 50),
createRect(WIDTH/12, texto2.sizeImg.y + 130, 4 * WIDTH/12, 0.10 * HEIGHT)
);
texto4 = setElement( //texto1 = nao
"texto4",
TTF_RenderText_Solid(fonte1, nao, color),
createRect(0, 0, 10*48, 50),
createRect(7 * WIDTH/12, texto2.sizeImg.y + 130, 4 * WIDTH/12, 0.10 * HEIGHT)
);
char nome1[nove], nome2[nove], nome3[nove], nome4[nove], nome5[nove], nome6[nove];
int numeros[9], ponto_jogador, novo_recorde = 0;
FILE *recorde;
FILE *grava;
grava = fopen( "apoio.txt", "r");
fscanf(grava, "%d", &ponto_jogador);
fclose(grava);
recorde = fopen( "recordes.txt", "r");
fscanf(recorde, "%s", nome1);
fscanf(recorde, "%d", &numeros[0]);
fscanf(recorde, "%s", nome2);
fscanf(recorde, "%d", &numeros[1]);
fscanf(recorde, "%s", nome3);
fscanf(recorde, "%d", &numeros[2]);
fscanf(recorde, "%s", nome4);
fscanf(recorde, "%d", &numeros[3]);
fscanf(recorde, "%s", nome5);
fscanf(recorde, "%d", &numeros[4]);
fscanf(recorde, "%s", nome6);
fscanf(recorde, "%d", &numeros[5]);
fclose(recorde);
for(int i = 0; i < 6; i++)
{
if(ponto_jogador > numeros[i])
{
novo_recorde = 1;
break;
}
}
playSong(16);
int tempo = 0;
while( 1 )
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
Mix_Quit();
TTF_Quit();
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.scancode)
{
case SDL_SCANCODE_LEFT:
if(continues > 0){
playSound(0);
continues--;
corte(janela, renderer);
}
break;
case SDL_SCANCODE_RIGHT:
playSound(0);
if(novo_recorde == 1){gravar_recorde(janela, renderer);}
else {endgame(janela, renderer);};
break;
case SDL_SCANCODE_RETURN:
playSound(0);
if(novo_recorde == 1){gravar_recorde(janela, renderer);}
else {endgame(janela, renderer);};
endgame(janela, renderer);
break;
}
break;
}
}
tempo++;
if(tempo>180){tempo=90;}
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texto1.Texture, &texto1.cut, &texto1.sizeImg);
if(continues > 0 && tempo >= 40)
{
SDL_RenderCopy(renderer, texto2.Texture, &texto2.cut, &texto2.sizeImg);
SDL_RenderCopy(renderer, texto3.Texture, &texto3.cut, &texto3.sizeImg);
SDL_RenderCopy(renderer, texto4.Texture, &texto4.cut, &texto4.sizeImg);
}
SDL_RenderPresent(renderer);
SDL_Delay(fps);
}
return;
}