Skip to content

Commit 6b387d5

Browse files
committed
feat: 🚑 inicio menu game over
1 parent 3d9ec53 commit 6b387d5

File tree

5 files changed

+210
-39
lines changed

5 files changed

+210
-39
lines changed

src/config/config.h

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ const char explosao_local[] = "src/images/explosao.png";
2525

2626
// fontes
2727
const char fonte_local[] = "src/fonts/ARCADE_N.TTF";
28-
const int tamanho_fonte = 18;
29-
3028
const char fonte_2_local[] = "src/fonts/ARCADE_I.TTF";
31-
const int tamanho_fonte_2_1 = 64;
32-
const int tamanho_fonte_2_2 = 24;
29+
const char fonte_3_local[] = "src/fonts/ARCADE_R.TTF";
30+
31+
const int tamanho_fonte_18 = 18;
32+
const int tamanho_fonte_64 = 64;
33+
const int tamanho_fonte_24 = 24;
34+
const int tamanho_fonte_26 = 24;
3335

3436
// sons
3537
const char tiro_som_local[] = "src/sounds/tiro.ogg";
@@ -43,6 +45,8 @@ ALLEGRO_TIMER *timer = NULL;
4345
ALLEGRO_FONT *fonte = NULL;
4446
ALLEGRO_FONT *fonte2_64 = NULL;
4547
ALLEGRO_FONT *fonte2_24 = NULL;
48+
ALLEGRO_FONT *fonte3_24 = NULL;
49+
ALLEGRO_FONT *fonte3_26 = NULL;
4650
ALLEGRO_EVENT ev;
4751
ALLEGRO_BITMAP *nave;
4852
ALLEGRO_BITMAP *arteroids;
@@ -156,6 +160,13 @@ char pontuacao_game_over_texto[] = "PONTOS: ";
156160
char recorde_game_over_texto[] = "RECORDE: ";
157161
char bateu_recorde_game_over_texto[] = "NOVO RECORDE!";
158162

163+
char menu_texto[] = "MENU";
164+
double menu_texto_animacao = 0.0;
165+
char reiniciar_texto[] = "REINICIAR";
166+
double reiniciar_texto_animacao = 0.0;
167+
168+
bool menu_game_over[2] = {true, false};
169+
159170
// declarando funções
160171
int iniciarAllegro();
161172
int finalizaAllegro();
@@ -238,10 +249,12 @@ int iniciarAllegro()
238249
}
239250

240251
//carrega os arquivos de fonte e define o tamanho que sera usado
241-
fonte = al_load_font(fonte_local, tamanho_fonte, 0);
242-
fonte2_64 = al_load_font(fonte_2_local, tamanho_fonte_2_1, 0);
243-
fonte2_24 = al_load_font(fonte_2_local, tamanho_fonte_2_2, 0);
244-
if(fonte == NULL || fonte2_64 == NULL || fonte2_24 == NULL) {
252+
fonte = al_load_font(fonte_local, tamanho_fonte_18, 0);
253+
fonte2_64 = al_load_font(fonte_2_local, tamanho_fonte_64, 0);
254+
fonte2_24 = al_load_font(fonte_2_local, tamanho_fonte_24, 0);
255+
fonte3_24 = al_load_font(fonte_3_local, tamanho_fonte_24, 0);
256+
fonte3_26 = al_load_font(fonte_3_local, tamanho_fonte_26, 0);
257+
if(fonte == NULL || fonte2_64 == NULL || fonte2_24 == NULL || fonte3_24 == NULL || fonte3_26 == NULL) {
245258
fprintf(stderr, "arquivo de fonte nao pode ser encontrado!\n");
246259
}
247260

src/events/teclas.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,28 @@ void eventoPressionarTecla()
1111
imprimirTeclaPressionada(ev.keyboard.keycode);
1212
}
1313

14-
teclasMovimentoNave(ev.keyboard.keycode, 1);
15-
teclasTiro(ev.keyboard.keycode, 1);
14+
if(!nave_game_over)
15+
{
16+
teclasMovimentoNave(ev.keyboard.keycode, 1);
17+
teclasTiro(ev.keyboard.keycode, 1);
18+
}
19+
else
20+
{
21+
teclasGameOver(ev.keyboard.keycode, 1);
22+
}
23+
1624
}
1725
else if(ev.type == ALLEGRO_EVENT_KEY_UP)
1826
{
19-
teclasMovimentoNave(ev.keyboard.keycode, 2);
20-
teclasTiro(ev.keyboard.keycode, 2);
27+
if(!nave_game_over)
28+
{
29+
teclasMovimentoNave(ev.keyboard.keycode, 2);
30+
teclasTiro(ev.keyboard.keycode, 2);
31+
}
32+
else
33+
{
34+
teclasGameOver(ev.keyboard.keycode, 2);
35+
}
2136
}
2237
}
2338

src/objects/gameover.h

Lines changed: 168 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
void escurecerTela();
22
void desenhaGameOver();
3+
void desenhaTelaEscurecida();
4+
void desenhaTextosGameOver();
5+
void denhaMenuGameOver();
6+
void animacaoPalavraMenu();
7+
void animacaoPalavraReiniciar();
8+
void desenhaPalavraMenu();
9+
void desenhaPalavraReiniciar();
310

411
void desenhaGameOver()
512
{
@@ -12,37 +19,173 @@ void desenhaGameOver()
1219
}
1320
else
1421
{
15-
int numero_digitos_pontos = (pontuacao == 0) ? 1 : log10(pontuacao) + 1;
16-
int numero_digitos_recorde = (recorde == 0) ? 1 : log10(recorde) + 1;
17-
18-
char p[numero_digitos_pontos];
19-
char r[numero_digitos_recorde];
20-
itoa(pontuacao, p, 10);
21-
itoa(recorde, r, 10);
22-
2322
// mantém a tela escurecida
24-
al_draw_filled_rectangle(0, 0, SCREEN_W, SCREEN_H, al_map_rgba(1, 1, 1, 200));
23+
desenhaTelaEscurecida();
2524

2625
// desenha o game over
27-
al_draw_text(fonte2_64, al_map_rgba(255, 255, 255, 1), SCREEN_W / 2, 2 * SCREEN_H / 8, ALLEGRO_ALIGN_CENTRE, game_over_texto);
28-
29-
// se o jogador bateu o recorde
30-
if(bateu_recorde)
31-
{
32-
// parabeniza o jogador pelo recorde
33-
al_draw_text(fonte2_24, al_map_rgba(255, 255, 255, 1), SCREEN_W / 2, 3.5 * SCREEN_H / 8, ALLEGRO_ALIGN_CENTRE, bateu_recorde_game_over_texto);
34-
}
35-
36-
// desenha a pontuação
37-
al_draw_text(fonte2_24, al_map_rgba(255, 255, 255, 1), SCREEN_W / 2, 4.5 * SCREEN_H / 8, ALLEGRO_ALIGN_CENTRE, concat(pontuacao_game_over_texto, p));
38-
39-
// desenha o recorde
40-
al_draw_text(fonte2_24, al_map_rgba(255, 255, 255, 1), SCREEN_W / 2, 5 * SCREEN_H / 8, ALLEGRO_ALIGN_CENTRE, concat(recorde_game_over_texto, r));
41-
42-
26+
desenhaTextosGameOver();
27+
28+
// desenha menu de opções no game over
29+
denhaMenuGameOver();
4330
}
31+
}
32+
}
33+
34+
void denhaMenuGameOver()
35+
{
36+
if(menu_game_over[0])
37+
{
38+
animacaoPalavraMenu();
39+
desenhaPalavraReiniciar();
40+
}
41+
else if(menu_game_over[1])
42+
{
43+
animacaoPalavraReiniciar();
44+
desenhaPalavraMenu();
45+
}
46+
}
4447

48+
void teclasGameOver(int tecla, int tipoEvento)
49+
{
50+
if(tipoEvento == 1)
51+
{
52+
switch(tecla) {
53+
//se a tecla for o W ou a seta para cima, ou S ou para baixo, troca para a opção
54+
case ALLEGRO_KEY_W:
55+
if(menu_game_over[0] == true)
56+
{
57+
menu_game_over[0] = false;
58+
menu_game_over[1] = true;
59+
}
60+
else
61+
{
62+
menu_game_over[0] = true;
63+
menu_game_over[1] = false;
64+
}
65+
break;
66+
case ALLEGRO_KEY_UP:
67+
if(menu_game_over[0] == true)
68+
{
69+
menu_game_over[0] = false;
70+
menu_game_over[1] = true;
71+
}
72+
else
73+
{
74+
menu_game_over[0] = true;
75+
menu_game_over[1] = false;
76+
}
77+
break;
78+
case ALLEGRO_KEY_S:
79+
if(menu_game_over[0] == true)
80+
{
81+
menu_game_over[0] = false;
82+
menu_game_over[1] = true;
83+
}
84+
else
85+
{
86+
menu_game_over[0] = true;
87+
menu_game_over[1] = false;
88+
}
89+
break;
90+
case ALLEGRO_KEY_DOWN:
91+
if(menu_game_over[0] == true)
92+
{
93+
menu_game_over[0] = false;
94+
menu_game_over[1] = true;
95+
}
96+
else
97+
{
98+
menu_game_over[0] = true;
99+
menu_game_over[1] = false;
100+
}
101+
break;
102+
}
103+
}
104+
}
105+
106+
void desenhaPalavraMenu()
107+
{
108+
al_draw_text(fonte3_24, al_map_rgba(255, 255, 255, 1), SCREEN_W / 2, 6 * SCREEN_H / 8, ALLEGRO_ALIGN_CENTRE, menu_texto);
109+
}
110+
111+
void desenhaPalavraReiniciar()
112+
{
113+
al_draw_text(fonte3_24, al_map_rgba(255, 255, 255, 1), SCREEN_W / 2, 6.5 * SCREEN_H / 8, ALLEGRO_ALIGN_CENTRE, reiniciar_texto);
114+
}
115+
116+
void animacaoPalavraReiniciar()
117+
{
118+
double tpm = 0.00;
119+
120+
if(reiniciar_texto_animacao <= 1)
121+
{
122+
tpm = reiniciar_texto_animacao;
123+
al_draw_text(fonte3_24, al_map_rgba(255 * tpm, 255 * tpm, 255 * tpm, tpm), SCREEN_W / 2, 6.5 * SCREEN_H / 8, ALLEGRO_ALIGN_CENTRE, reiniciar_texto);
124+
reiniciar_texto_animacao += 0.02;
45125
}
126+
else if(reiniciar_texto_animacao <= 2)
127+
{
128+
tpm = 1 - (reiniciar_texto_animacao - 1);
129+
al_draw_text(fonte3_26, al_map_rgba(255 * tpm, 255 * tpm, 255 * tpm, tpm), SCREEN_W / 2, 6.5 * SCREEN_H / 8, ALLEGRO_ALIGN_CENTRE, reiniciar_texto);
130+
reiniciar_texto_animacao += 0.02;
131+
}
132+
else
133+
{
134+
reiniciar_texto_animacao = 0;
135+
}
136+
}
137+
138+
void animacaoPalavraMenu()
139+
{
140+
double tpm = 0.00;
141+
142+
if(menu_texto_animacao <= 1)
143+
{
144+
tpm = menu_texto_animacao;
145+
al_draw_text(fonte3_24, al_map_rgba(255 * tpm, 255 * tpm, 255 * tpm, tpm), SCREEN_W / 2, 6 * SCREEN_H / 8, ALLEGRO_ALIGN_CENTRE, menu_texto);
146+
menu_texto_animacao += 0.02;
147+
}
148+
else if(menu_texto_animacao <= 2)
149+
{
150+
tpm = 1 - (menu_texto_animacao - 1);
151+
al_draw_text(fonte3_26, al_map_rgba(255 * tpm, 255 * tpm, 255 * tpm, tpm), SCREEN_W / 2, 6 * SCREEN_H / 8, ALLEGRO_ALIGN_CENTRE, menu_texto);
152+
menu_texto_animacao += 0.02;
153+
}
154+
else
155+
{
156+
menu_texto_animacao = 0;
157+
}
158+
}
159+
160+
void desenhaTextosGameOver()
161+
{
162+
int numero_digitos_pontos = (pontuacao == 0) ? 1 : log10(pontuacao) + 1;
163+
int numero_digitos_recorde = (recorde == 0) ? 1 : log10(recorde) + 1;
164+
165+
char p[numero_digitos_pontos];
166+
char r[numero_digitos_recorde];
167+
itoa(pontuacao, p, 10);
168+
itoa(recorde, r, 10);
169+
170+
al_draw_text(fonte2_64, al_map_rgba(255, 255, 255, 1), SCREEN_W / 2, 1 * SCREEN_H / 8, ALLEGRO_ALIGN_CENTRE, game_over_texto);
171+
172+
// se o jogador bateu o recorde
173+
if(bateu_recorde)
174+
{
175+
// parabeniza o jogador pelo recorde
176+
al_draw_text(fonte2_24, al_map_rgba(255, 255, 255, 1), SCREEN_W / 2, 2.5 * SCREEN_H / 8, ALLEGRO_ALIGN_CENTRE, bateu_recorde_game_over_texto);
177+
}
178+
179+
// desenha a pontuação
180+
al_draw_text(fonte2_24, al_map_rgba(255, 255, 255, 1), SCREEN_W / 2, 3.5 * SCREEN_H / 8, ALLEGRO_ALIGN_CENTRE, concat(pontuacao_game_over_texto, p));
181+
182+
// desenha o recorde
183+
al_draw_text(fonte2_24, al_map_rgba(255, 255, 255, 1), SCREEN_W / 2, 4 * SCREEN_H / 8, ALLEGRO_ALIGN_CENTRE, concat(recorde_game_over_texto, r));
184+
}
185+
186+
void desenhaTelaEscurecida()
187+
{
188+
al_draw_filled_rectangle(0, 0, SCREEN_W, SCREEN_H, al_map_rgba(1, 1, 1, 200));
46189
}
47190

48191
void escurecerTela()

src/objects/menu.h

Whitespace-only changes.

src/objects/tiro.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ void teclasTiro(int tecla, int tipoEvento)
713713
if(tipoEvento == 1)
714714
{
715715
switch(tecla) {
716-
//se a tecla for o W
716+
//se a tecla for o espaço
717717
case ALLEGRO_KEY_SPACE:
718718
inicio_tiro = al_get_time ();
719719
segurando_tecla = true;
@@ -725,7 +725,7 @@ void teclasTiro(int tecla, int tipoEvento)
725725
{
726726
//verifica qual tecla foi
727727
switch(tecla) {
728-
//se a tecla for o W
728+
//se a tecla for o espaço
729729
case ALLEGRO_KEY_SPACE:
730730
duracao_tiro = al_get_time() - inicio_tiro;
731731
tiroTecla = true;

0 commit comments

Comments
 (0)