Skip to content

Commit 4f36ad7

Browse files
committed
feat: ✨ adicionado opção de reiniciar o jogo
1 parent 6b387d5 commit 4f36ad7

File tree

9 files changed

+109
-7
lines changed

9 files changed

+109
-7
lines changed

src/autoload.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
#include "objects/bloco.h"
3030
#include "objects/asteroid.h"
3131
#include "objects/extended/calculosBloco.h"
32+
#include "objects/extended/gameOverReinicia.h"
3233
#include "objects/tiro.h"
3334
#include "objects/nave.h"
35+
#include "objects/jogo.h"
3436
#include "objects/gameover.h"
3537
#include "objects/tela.h"
3638

src/config/config.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ bool colisao = false;
6666
int animacaoColisao = 1;
6767

6868
// coordenadas da nave
69-
int nave_dx = -12;
69+
const int inicio_dx_nave = -12;
70+
int nave_dx = 0;
7071
int nave_dy = 0;
7172
int movimentacaoNave = 4;
7273

@@ -154,6 +155,8 @@ const char recorde_arquivo[] = "src/data/recorde.txt";
154155
bool bateu_recorde = false;
155156

156157
// game over
158+
bool estaNoTimePosReinicial = false;
159+
int gameOverReinicia = 0;
157160
bool nave_game_over = false;
158161
char game_over_texto[] = "GAME OVER";
159162
char pontuacao_game_over_texto[] = "PONTOS: ";
@@ -166,6 +169,7 @@ char reiniciar_texto[] = "REINICIAR";
166169
double reiniciar_texto_animacao = 0.0;
167170

168171
bool menu_game_over[2] = {true, false};
172+
bool menu_game_over_selecionado = false;
169173

170174
// declarando funções
171175
int iniciarAllegro();

src/events/temporizador.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ void eventosDeTemporizador()
1616
{
1717
pontuacao++;
1818
}
19-
19+
2020
if(DEBUG == true)
2121
{
2222
// mostra os segundos se passando ao longo do jogo
2323
mostrarSegundosPassando();
2424
}
2525

26+
if(estaNoTimePosReinicial)
27+
{
28+
verificaGameOverReinicia();
29+
}
2630
}
2731
}
2832

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
bool verificaGameOverReinicia();
2+
3+
bool verificaGameOverReinicia()
4+
{
5+
if(estaNoTimePosReinicial)
6+
{
7+
// incrementa contador pós game over
8+
gameOverReinicia++;
9+
10+
if(gameOverReinicia > 60)
11+
{
12+
gameOverReinicia = 0;
13+
estaNoTimePosReinicial = false;
14+
return true;
15+
}
16+
else
17+
{
18+
return false;
19+
}
20+
}
21+
else
22+
{
23+
return true;
24+
}
25+
}

src/objects/gameover.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ void denhaMenuGameOver()
4242
{
4343
animacaoPalavraReiniciar();
4444
desenhaPalavraMenu();
45+
46+
if(menu_game_over_selecionado)
47+
{
48+
menu_game_over_selecionado = false;
49+
reiniciarJogo();
50+
}
4551
}
4652
}
4753

@@ -50,7 +56,11 @@ void teclasGameOver(int tecla, int tipoEvento)
5056
if(tipoEvento == 1)
5157
{
5258
switch(tecla) {
53-
//se a tecla for o W ou a seta para cima, ou S ou para baixo, troca para a opção
59+
// se o usuario selecionou uma opção
60+
case ALLEGRO_KEY_SPACE:
61+
menu_game_over_selecionado = true;
62+
break;
63+
//se a tecla for o W ou a seta para cima, ou S ou para baixo, troca para a opção
5464
case ALLEGRO_KEY_W:
5565
if(menu_game_over[0] == true)
5666
{
@@ -101,6 +111,15 @@ void teclasGameOver(int tecla, int tipoEvento)
101111
break;
102112
}
103113
}
114+
else if(tipoEvento == 2)
115+
{
116+
switch(tecla) {
117+
// se o usuario selecionou uma opção
118+
case ALLEGRO_KEY_SPACE:
119+
menu_game_over_selecionado = false;
120+
break;
121+
}
122+
}
104123
}
105124

106125
void desenhaPalavraMenu()

src/objects/jogo.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
void reiniciarJogo();
2+
3+
void reiniciarJogo()
4+
{
5+
// reinicia o jogo
6+
estaNoTimePosReinicial = true;
7+
gameOverReinicia = al_get_time();
8+
9+
// desativa toda a movimentação da nave
10+
move_up = false;
11+
move_down = false;
12+
move_left = false;
13+
move_right = false;
14+
15+
// retira a nave do modo de colisao
16+
colisao = false;
17+
animacaoColisao = 0;
18+
19+
// reinicia os asteroides
20+
for (int i = 0; i < quantidadeArteroids; i++)
21+
{
22+
asteroid[i].colisao = true;
23+
asteroid[i].status = false;
24+
}
25+
26+
// reinicia o bloco
27+
bloco.x = (-2 * bloco.largura);
28+
29+
// reinicia posicao nave
30+
nave_dx = inicio_dx_nave;
31+
nave_dy = (SCREEN_H / 2) - NAVE_W / 2;
32+
33+
// reiniciar todos os tiros
34+
limpaTiros();
35+
36+
// desativa o calculo de tiro
37+
tiroTecla = false;
38+
39+
// reinicia pontuacao
40+
pontuacao = 0;
41+
42+
// reinicia o game over
43+
nave_game_over = false;
44+
}

src/objects/menu.h

Whitespace-only changes.

src/objects/nave.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ void desenhaAnimacaoNave();
1010

1111
void iniciaNave()
1212
{
13-
nave_dy = (SCREEN_H / 2) - NAVE_W / 2;
13+
nave_dx = inicio_dx_nave;
14+
nave_dy = (SCREEN_H / 2) - NAVE_W / 2;
1415
al_draw_bitmap_region(nave, 3 * NAVE_W, NAVE_H, NAVE_W, NAVE_H, nave_dx, nave_dy, 0);
1516
}
1617

src/objects/tiro.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,12 @@ void teclasTiro(int tecla, int tipoEvento)
727727
switch(tecla) {
728728
//se a tecla for o espaço
729729
case ALLEGRO_KEY_SPACE:
730-
duracao_tiro = al_get_time() - inicio_tiro;
731-
tiroTecla = true;
732-
segurando_tecla = false;
730+
if(verificaGameOverReinicia())
731+
{
732+
duracao_tiro = al_get_time() - inicio_tiro;
733+
tiroTecla = true;
734+
segurando_tecla = false;
735+
}
733736
break;
734737
}
735738
}

0 commit comments

Comments
 (0)