├── README.md
├── bola.py
├── constantes.py
├── imagens
├── bolinha.png
├── imagem_inicio.png
├── musicaDeslig.png
├── musicaLig.png
├── raquete1.png
├── raquete2.png
├── regra1.png
├── regra2.png
├── regra3.png
├── setaDireita.png
└── setaEsquerda.png
├── img
├── modo_multijogador.png
├── tela_final_de_partida.png
└── tela_menu.png
├── principal.py
├── raquete.py
├── requirements.txt
├── sons
├── som_aplausos.ogg
├── som_menu.ogg
├── som_mesa.ogg
├── som_raquete.ogg
└── som_seta.ogg
├── sorteio.py
├── tela_inicio.py
├── tela_menu.py
├── tela_multijogador.py
├── tela_regras.py
└── tela_treinamento.py
/README.md:
--------------------------------------------------------------------------------
1 |
🏓 Tênis de mesa 🏓
2 |
3 | 
4 |
5 | ### 📜 Requisitos:
6 |
7 | * Python3
8 | * Pip (Python Package Index)
9 | * Biblioteca `pygame` instalada no PC
10 |
11 | ### 📝 Dependências:
12 | pip install -r requirements.txt
13 |
14 | ### ⬇️ Download e ✔️ Instalação:
15 | Após instalar as dependências, clone o repositório em seu PC da maneira que preferir. Por exemplo, copie e cole a linha abaixo no seu programa padrão de linha de comando:
16 |
17 | git clone git@github.com:maxbarbosa/TableTennisPygame.git
18 |
19 | Tela de Menu
20 |
21 | 
22 |
23 | # 🎮 Controles:
24 | * Utilize as teclas ⬇️ e ⬆️ para selecionar a opção desejada na tela de menu usando a tecla `Enter`
25 | * Utilize a tecla `ESC` para silenciar a música
26 | * Utilize a tecla `TAB` para habilitar a música
27 | * Para controlar o _Jogador A_, utilize as teclas 🇼, 🇦, 🇸, 🇩
28 | * Para controlar o _Jogador B_, utilize as teclas ⬆️, ⬅️, ⬇️, ➡️
29 | * Para posicionar a bolinha durante o saque utilize as teclas 🇹 e 🇬
30 | * Para retornar à tela de menu, utilize a tecla `ESC`
31 |
32 | ### ❌ Desinstalando:
33 | Caso queira desinstalar o jogo de sua máquina, basta apenas excluir a pasta *TableTennisPygame*.
34 |
--------------------------------------------------------------------------------
/bola.py:
--------------------------------------------------------------------------------
1 | #CONTROLANDO A POSIÇÃO DA BOLINHA DURANTE O SAQUE
2 | def B_praCima (y_bolinha, limite):
3 | y_bolinha -= 5
4 |
5 | if y_bolinha < limite:
6 | y_bolinha = limite
7 |
8 | return y_bolinha
9 |
10 | def B_praBaixo (y_bolinha, limite):
11 | y_bolinha += 5
12 |
13 | if y_bolinha > limite:
14 | y_bolinha = limite
15 |
16 | return y_bolinha
17 |
18 | #POSICIONANDO O SAQUE DE ACORDO COM O RESULTADO DO SORTEIO
19 | def posicionarSaque (posicao_seta):
20 | posicao_saque = []
21 |
22 | if posicao_seta == [850, 15]:
23 | posicao_saque = [92, 359]
24 | else:
25 | posicao_saque = [1005, 359]
26 |
27 | return posicao_saque
--------------------------------------------------------------------------------
/constantes.py:
--------------------------------------------------------------------------------
1 | import pygame
2 |
3 | #TÍTULO DA JANELA
4 | titulo_janela = "TÊNIS DE MESA"
5 |
6 | #RESOLUÇÃO DA JANELA
7 | largura = 1120
8 | altura = 656
9 |
10 | #FPS
11 | fps = 60
12 | relogio = pygame.time.Clock()
13 |
14 | #DEFININDO AS PROPRIEDADES DA JANELA
15 | tela = pygame.display.set_mode((largura, altura))
16 | pygame.display.set_caption(titulo_janela)
17 |
18 | #TABELA DE CORES
19 | cor_preta = (1, 1, 1)
20 | cor_branca = (255, 255, 255)
21 | cor_cinza = (28, 28, 28)
22 | cor_verde = (0, 100, 0)
23 | cor_vermelha = (255, 0, 0)
24 | cor_da_mesa = (25, 25, 112)
25 | cor_da_borda = (211, 211, 211)
26 | cor_da_rede = (211, 211, 211)
27 | plano_de_fundo_partida = (107, 142, 35)
28 | plano_de_fundo_menu = (205, 133, 63)
29 | cor_opcao = (75, 0, 130)
30 |
31 | #IMAGENS
32 | img_inicio = 'imagens/imagem_inicio.png'
33 | img_musicaLig = 'imagens/musicaLig.png'
34 | img_musicaDeslig = 'imagens/musicaDeslig.png'
35 | img_regra1 = 'imagens/regra1.png'
36 | img_regra2 = 'imagens/regra2.png'
37 | img_regra3 = 'imagens/regra3.png'
38 | img_seta_direita = 'imagens/setaDireita.png'
39 | img_seta_esquerda = 'imagens/setaEsquerda.png'
40 | img_bolinha = 'imagens/bolinha.png'
41 | img_raquete1 = 'imagens/raquete1.png'
42 | img_raquete2 = 'imagens/raquete2.png'
43 |
44 | #FONTE
45 | fonte = 'verdana'
46 |
--------------------------------------------------------------------------------
/imagens/bolinha.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/imagens/bolinha.png
--------------------------------------------------------------------------------
/imagens/imagem_inicio.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/imagens/imagem_inicio.png
--------------------------------------------------------------------------------
/imagens/musicaDeslig.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/imagens/musicaDeslig.png
--------------------------------------------------------------------------------
/imagens/musicaLig.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/imagens/musicaLig.png
--------------------------------------------------------------------------------
/imagens/raquete1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/imagens/raquete1.png
--------------------------------------------------------------------------------
/imagens/raquete2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/imagens/raquete2.png
--------------------------------------------------------------------------------
/imagens/regra1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/imagens/regra1.png
--------------------------------------------------------------------------------
/imagens/regra2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/imagens/regra2.png
--------------------------------------------------------------------------------
/imagens/regra3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/imagens/regra3.png
--------------------------------------------------------------------------------
/imagens/setaDireita.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/imagens/setaDireita.png
--------------------------------------------------------------------------------
/imagens/setaEsquerda.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/imagens/setaEsquerda.png
--------------------------------------------------------------------------------
/img/modo_multijogador.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/img/modo_multijogador.png
--------------------------------------------------------------------------------
/img/tela_final_de_partida.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/img/tela_final_de_partida.png
--------------------------------------------------------------------------------
/img/tela_menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/img/tela_menu.png
--------------------------------------------------------------------------------
/principal.py:
--------------------------------------------------------------------------------
1 | import tela_inicio
2 | tela_inicio.exibir_imagem_inicio()
3 |
--------------------------------------------------------------------------------
/raquete.py:
--------------------------------------------------------------------------------
1 | #CONTROLANDO AS AÇÕES DA RAQUETE
2 | def R_praCima(y_rqt, limite):
3 | y_rqt -= 5
4 |
5 | if y_rqt < limite:
6 | y_rqt = limite
7 |
8 | return y_rqt
9 |
10 | def R_praBaixo(y_rqt, limite):
11 | y_rqt += 5
12 |
13 | if y_rqt > limite:
14 | y_rqt = limite
15 |
16 | return y_rqt
17 |
18 | def R_praEsquerda(x_rqt, limite):
19 | x_rqt -= 5
20 |
21 | if x_rqt < limite:
22 | x_rqt = limite
23 |
24 | return x_rqt
25 |
26 | def R_praDireita(x_rqt, limite):
27 | x_rqt += 5
28 |
29 | if x_rqt > limite:
30 | x_rqt = limite
31 |
32 | return x_rqt
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | pygame
2 |
--------------------------------------------------------------------------------
/sons/som_aplausos.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/sons/som_aplausos.ogg
--------------------------------------------------------------------------------
/sons/som_menu.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/sons/som_menu.ogg
--------------------------------------------------------------------------------
/sons/som_mesa.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/sons/som_mesa.ogg
--------------------------------------------------------------------------------
/sons/som_raquete.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/sons/som_raquete.ogg
--------------------------------------------------------------------------------
/sons/som_seta.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbarbosa/TableTennisPygame/ae26261dc7d3374a89af076757db2e3d6780bfdc/sons/som_seta.ogg
--------------------------------------------------------------------------------
/sorteio.py:
--------------------------------------------------------------------------------
1 | #REALIZANDO O SORTEIO PARA VER QUAL DOS DOIS JOGADORES COMEÇARÁ SACANDO
2 | import pygame
3 | from random import randint
4 |
5 | def sortearSaque():
6 | posicao_seta = []
7 | vez_jogador = randint(0, 1)
8 |
9 | if vez_jogador == 0:
10 | posicao_seta = [850, 15]
11 | else:
12 | posicao_seta = [850, 55]
13 |
14 | return posicao_seta
15 |
16 | #CONTROLANDO AS SETAS NO MENU PRINCIPAL DO JOGO
17 | def S_praCima(y_opcao, limite):
18 | y_opcao -= 100
19 |
20 | if y_opcao < limite:
21 | y_opcao = limite
22 |
23 | return y_opcao
24 |
25 | def S_praBaixo(y_opcao, limite):
26 | y_opcao += 100
27 | if y_opcao > limite:
28 | y_opcao = limite
29 |
30 | return y_opcao
31 |
32 |
--------------------------------------------------------------------------------
/tela_inicio.py:
--------------------------------------------------------------------------------
1 | import pygame, tela_menu
2 | import constantes as const
3 | from sys import exit
4 | from pygame.locals import *
5 | from time import sleep
6 |
7 | def exibir_imagem_inicio():
8 |
9 | pygame.init()
10 |
11 | const.tela
12 |
13 | img_fundo = pygame.image.load(const.img_inicio)
14 |
15 | while True:
16 |
17 | for event in pygame.event.get():
18 | if event.type == QUIT:
19 | pygame.quit()
20 | exit()
21 |
22 | const.tela.blit(img_fundo, (0,0))
23 | pygame.display.flip()
24 |
25 | sleep(5)
26 | tela_menu.exibir_tela_menu()
--------------------------------------------------------------------------------
/tela_menu.py:
--------------------------------------------------------------------------------
1 | import pygame, tela_multijogador, tela_treinamento, tela_regras
2 | import constantes as const
3 | from sys import exit
4 | from pygame.locals import *
5 | from sorteio import *
6 | from time import sleep
7 |
8 | def exibir_tela_menu():
9 |
10 | pygame.init()
11 |
12 | const.tela
13 |
14 | #DEFININDO A FONTE USADA PARA EXIBIR AS OPÇÕES
15 | fonteOpcao = pygame.font.SysFont(const.fonte, 25, True)
16 |
17 | #CARREGANDO A IMAGEM DA SETA E REDIMENSIONANDO SEU TAMANHO
18 | img_seta1 = pygame.image.load(const.img_seta_direita)
19 | img_seta1 = pygame.transform.scale(img_seta1, (64, 64))
20 |
21 | x_seta1 = 330
22 | y_seta1 = 150
23 |
24 | img_seta2 = pygame.image.load(const.img_seta_esquerda)
25 | img_seta2 = pygame.transform.scale(img_seta2, (64, 64))
26 |
27 | x_seta2 = 726
28 | y_seta2 = 150
29 |
30 | #LISTA DE OPÇÕES DO MENU E A AUTORIA DA CRIAÇÃO DO JOGO
31 | opc1 = fonteOpcao.render("Multijogador", True, const.cor_branca)
32 | opc2 = fonteOpcao.render("Treinamento", True, const.cor_branca)
33 | opc3 = fonteOpcao.render("Regras", True, const.cor_branca)
34 | opc4 = fonteOpcao.render("Sair", True, const.cor_branca)
35 | autoria = fonteOpcao.render("© Maked by M&S", True, const.cor_preta)
36 |
37 | #CARREGANDO OS ÍCONES SONOROS E O ARQUIVO DE MÚSICA
38 | img_musica = pygame.image.load(const.img_musicaLig)
39 |
40 | x_musica = 25
41 | y_musica = 25
42 |
43 | som_menu = pygame.mixer.music.load('sons/som_menu.ogg')
44 | som_seta = pygame.mixer.Sound('sons/som_seta.ogg')
45 |
46 | pygame.mixer.music.play()
47 |
48 | while True:
49 | const.relogio.tick(const.fps)
50 |
51 | for event in pygame.event.get():
52 | if event.type == QUIT:
53 | pygame.quit()
54 | exit()
55 |
56 | const.tela.fill(const.plano_de_fundo_menu)
57 |
58 | pygame.draw.rect(const.tela, const.cor_opcao, (410, 140, 300, 80))
59 | pygame.draw.rect(const.tela, const.cor_opcao, (410, 240, 300, 80))
60 | pygame.draw.rect(const.tela, const.cor_opcao, (410, 340, 300, 80))
61 | pygame.draw.rect(const.tela, const.cor_opcao, (410, 440, 300, 80))
62 |
63 | const.tela.blit(opc1, (470, 160))
64 | const.tela.blit(opc2, (472, 260))
65 | const.tela.blit(opc3, (510, 360))
66 | const.tela.blit(opc4, (531, 460))
67 | const.tela.blit(autoria, (440, 600))
68 | const.tela.blit(img_musica, (x_musica, y_musica))
69 |
70 | #CONTROLANDO AS SETAS DO MENU
71 | tecla = pygame.key.get_pressed()
72 |
73 | if tecla[K_UP]:
74 | y_seta1 = S_praCima(y_seta1, 150)
75 | y_seta2 = S_praCima(y_seta2, 150)
76 |
77 | if tecla[K_DOWN]:
78 | y_seta1 = S_praBaixo(y_seta1, 450)
79 | y_seta2 = S_praBaixo(y_seta2, 450)
80 |
81 | #PARA A MÚSICA QUE TOCA NO MENU QUANDO ALGUMA OPÇÃO É SELECIONADA
82 | if tecla[K_RETURN]:
83 | pygame.mixer.music.stop()
84 |
85 | #CHAMANDO A TELA SELECIONADA COM BASE NA POSIÇÃO DA SETA
86 | if y_seta1 == 150 and tecla[K_RETURN]:
87 | tela_multijogador.exibir_tela_multijogador()
88 |
89 | if y_seta1 == 250 and tecla[K_RETURN]:
90 | tela_treinamento.exibir_tela_treinamento()
91 |
92 | if y_seta1 == 350 and tecla[K_RETURN]:
93 | tela_regras.exibir_tela_regras()
94 |
95 | if y_seta1 == 450 and tecla[K_RETURN]:
96 | pygame.quit()
97 | exit()
98 |
99 | const.tela.blit(img_seta1, (x_seta1, y_seta1))
100 | const.tela.blit(img_seta2, (x_seta2, y_seta2))
101 |
102 | pygame.display.flip()
103 |
104 | if tecla[K_ESCAPE]:
105 | img_musica = pygame.image.load(const.img_musicaDeslig)
106 | pygame.mixer.music.stop()
107 | if tecla[K_TAB]:
108 | img_musica = pygame.image.load(const.img_musicaLig)
109 | pygame.mixer.music.play()
110 |
111 | #ADICIONANDO UM PEQUENO DELAY AO MOVER AS SETAS
112 | if tecla[K_UP] or tecla[K_DOWN]:
113 | som_seta.play()
114 | sleep(0.27)
--------------------------------------------------------------------------------
/tela_multijogador.py:
--------------------------------------------------------------------------------
1 | import pygame, tela_menu
2 | import constantes as const
3 | from pygame.locals import *
4 | from sys import exit
5 | from sorteio import *
6 | from raquete import *
7 | from bola import *
8 | from random import randint
9 | from time import sleep
10 |
11 | def exibir_tela_multijogador():
12 |
13 | #PONTUAÇÃO
14 | sets_jogador1 = 0
15 | sets_jogador2 = 0
16 |
17 | pts_jogador1 = 0
18 | pts_jogador2 = 0
19 |
20 | pontos = 0
21 |
22 | vencedor = ""
23 |
24 | controlar_saque = True
25 | atrasar_saque = False
26 | contou_ponto = False
27 | acabou_set = False
28 | direita = False
29 | esquerda = False
30 | v_x_bolinha = 0
31 | v_y_bolinha = 0
32 |
33 | pygame.init()
34 |
35 | const.tela
36 |
37 | #DEFININDO A FONTE USADA PARA EXIBIR O PLACAR
38 | fonteTexto = pygame.font.SysFont(const.fonte, 18, True)
39 | fonteNumero = pygame.font.SysFont(const.fonte, 25, True)
40 | fonteAviso = pygame.font.SysFont(const.fonte, 45, True)
41 |
42 | imagem_seta = pygame.image.load(const.img_seta_direita)
43 | imagem_seta = pygame.transform.scale(imagem_seta, (32, 32))
44 | posicao_seta = sortearSaque()
45 |
46 | bola = pygame.image.load(const.img_bolinha)
47 | x_bola = posicionarSaque(posicao_seta)[0]
48 | y_bola = posicionarSaque(posicao_seta)[1]
49 |
50 | raquete1 = pygame.image.load(const.img_raquete1)
51 | x_rqt1 = 15
52 | y_rqt1 = 330
53 |
54 | raquete2 = pygame.image.load(const.img_raquete2)
55 | x_rqt2 = 1045
56 | y_rqt2 = 330
57 |
58 | #CRIAÇÃO DE MÁSCARAS PARA VERIFICAR COLISÕES ENTRE AS IMAGENS
59 | mascara_bola = pygame.mask.from_surface(bola)
60 | mascara_rqt1 = pygame.mask.from_surface(raquete1)
61 | mascara_rqt2 = pygame.mask.from_surface(raquete2)
62 |
63 | som_raquete = pygame.mixer.Sound('sons/som_raquete.ogg')
64 | som_mesa = pygame.mixer.Sound('sons/som_mesa.ogg')
65 | som_aplausos = pygame.mixer.Sound('sons/som_aplausos.ogg')
66 |
67 | while True:
68 | const.relogio.tick(const.fps)
69 |
70 | for event in pygame.event.get():
71 | if event.type == QUIT:
72 | pygame.quit()
73 | exit()
74 |
75 | #DESENHANDO A REGIÃO DO PLANO DE FUNDO, PLACAR E MESA
76 | const.tela.fill(const.plano_de_fundo_partida)
77 | pygame.draw.rect(const.tela, const.cor_verde, (0, 0, const.largura, 120))
78 | pygame.draw.rect(const.tela, const.cor_cinza, (890, 15, 175, 70))
79 | pygame.draw.rect(const.tela, const.cor_da_borda, (1015, 15, 100, 70))
80 | pygame.draw.line(const.tela, const.cor_da_borda, (890, 50), (1035, 50), 1)
81 | pygame.draw.line(const.tela, const.cor_cinza, (1015, 50), (1114, 50), 1)
82 | pygame.draw.line(const.tela, const.cor_cinza, (1065, 15), (1065, 85), 1)
83 | pygame.draw.rect(const.tela, const.cor_da_mesa, (100, 120, 920, 500))
84 |
85 | #DESENHANDO AS BORDAS ESQUERDA E DIREITA DA MESA
86 | pygame.draw.line(const.tela, const.cor_da_borda, (104, 120), (104, 619), 10)
87 | pygame.draw.line(const.tela, const.cor_da_borda, (1014, 120), (1014, 619), 10)
88 |
89 | #DESENHANDO AS BORDAS SUPERIOR E INFERIOR DA MESA
90 | pygame.draw.line(const.tela, const.cor_da_borda, (100, 124), (1019, 124), 10)
91 | pygame.draw.line(const.tela, const.cor_da_borda, (100, 614), (1019, 614), 10)
92 |
93 | #DESENHANDO REDE E LINHA DIVISÓRIA DA MESA
94 | pygame.draw.line(const.tela, const.cor_da_rede, (559, 124), (559, 614), 10)
95 | pygame.draw.aaline(const.tela, const.cor_da_rede, (100, 370), (1019, 370))
96 |
97 | tecla = pygame.key.get_pressed()
98 |
99 | if tecla[K_ESCAPE]:
100 | tela_menu.exibir_tela_menu()
101 |
102 | #AÇÕES DO 1º JOGADOR
103 | if tecla[K_w]:
104 | y_rqt1 = R_praCima(y_rqt1, 120)
105 | if tecla[K_a]:
106 | x_rqt1 = R_praEsquerda(x_rqt1, 0)
107 | if tecla[K_s]:
108 | y_rqt1 = R_praBaixo(y_rqt1, 530)
109 | if tecla[K_d]:
110 | x_rqt1 = R_praDireita(x_rqt1, 240)
111 |
112 | #AÇÕES DO 2º JOGADOR
113 | if tecla[K_UP]:
114 | y_rqt2 = R_praCima(y_rqt2, 120)
115 | if tecla[K_LEFT]:
116 | x_rqt2 = R_praEsquerda(x_rqt2, 816)
117 | if tecla[K_DOWN]:
118 | y_rqt2 = R_praBaixo(y_rqt2, 530)
119 | if tecla[K_RIGHT]:
120 | x_rqt2 = R_praDireita(x_rqt2, 1056)
121 |
122 | #RETORNA A POSIÇÃO DA BOLINHA EM RELAÇÃO ÀS RAQUETES
123 | sobreposicao1 = (x_bola - x_rqt1, y_bola - y_rqt1)
124 | sobreposicao2 = (x_bola - x_rqt2, y_bola - y_rqt2)
125 |
126 | #A FUNÇÃO OVERLAP RETORNA O PONTO DE INTERSEÇÃO
127 | #DO PRIMEIRO PARÂMETRO QUE É UMA
128 | #MÁSCARA E O DESLOCAMENTO DA SEGUNDA IMAGEM
129 | colisao1 = mascara_rqt1.overlap(mascara_bola, sobreposicao1)
130 | colisao2 = mascara_rqt2.overlap(mascara_bola, sobreposicao2)
131 |
132 | #CONTROLANDO A BOLINHA DURANTE O SAQUE
133 | if controlar_saque == True and not colisao1 and not colisao2:
134 | if tecla[K_t]:
135 | y_bola = B_praCima(y_bola, 130)
136 | if tecla[K_g]:
137 | y_bola = B_praBaixo(y_bola, 585)
138 |
139 | #MOVIMENTANDO A BOLINHA A PARTIR DA COLISÃO DA BOLINHA COM UMA RAQUETE
140 | if colisao1 or colisao2:
141 | som_raquete.play()
142 | controlar_saque = False
143 |
144 | v_x_bolinha = randint(7, 9)
145 | v_y_bolinha = randint(-6, 6)
146 |
147 | if colisao1:
148 | direita = True
149 | esquerda = False
150 |
151 | if colisao2:
152 | direita = False
153 | esquerda = True
154 |
155 | if direita:
156 | x_bola += v_x_bolinha
157 | if esquerda:
158 | x_bola -= v_x_bolinha
159 |
160 | y_bola += v_y_bolinha
161 |
162 | #VERIFICANDO SE A BOLINHA PASSOU DOS LIMITES DA TELA
163 | if x_bola < -32 or x_bola > 1130:
164 | contou_ponto = True
165 | controlar_saque = True
166 | atrasar_saque = True
167 | direita = False
168 | esquerda = False
169 |
170 | x_rqt1 = 15
171 | y_rqt1 = 330
172 |
173 | x_rqt2 = 1045
174 | y_rqt2 = 330
175 |
176 | if x_bola > 1130:
177 | pts_jogador1 += 1
178 | v_y_bolinha = 0
179 |
180 | if x_bola < -32:
181 | pts_jogador2 += 1
182 | v_y_bolinha = 0
183 |
184 | #VERIFICANDO SE A BOLINHA ALCANÇOU AS BORDAS SUPERIOR E INFERIOR DA MESA
185 | if(y_bola < 130):
186 | som_mesa.play()
187 | y_bola = 130
188 | v_y_bolinha = -v_y_bolinha
189 |
190 | if(y_bola > 585):
191 | som_mesa.play()
192 | y_bola = 585
193 | v_y_bolinha = -v_y_bolinha
194 |
195 | #VERIFICANDO SE O JOGADOR1 GANHOU O SET
196 | if pts_jogador1 >= 11 and pts_jogador1-pts_jogador2 > 1:
197 | sets_jogador1 += 1
198 |
199 | if sets_jogador1 < 4:
200 | exibirVencedorSet = fonteAviso.render("Jogador A venceu o set por %d a %d" %(pts_jogador1, pts_jogador2), True, const.cor_vermelha)
201 | const.tela.blit(exibirVencedorSet, (150, 160))
202 |
203 | acabou_set = True
204 | pts_jogador1 = 0
205 | pts_jogador2 = 0
206 | v_x_bolinha = 0
207 | v_y_bolinha = 0
208 |
209 | #VERIFICANDO SE O JOGADOR2 GANHOU O SET
210 | if pts_jogador2 >= 11 and pts_jogador2-pts_jogador1 > 1:
211 | sets_jogador2 += 1
212 |
213 | if sets_jogador2 < 4:
214 | exibirVencedorSet = fonteAviso.render("Jogador B venceu o set por %d a %d" %(pts_jogador2, pts_jogador1), True, const.cor_vermelha)
215 | const.tela.blit(exibirVencedorSet, (150, 160))
216 |
217 | acabou_set = True
218 | pts_jogador1 = 0
219 | pts_jogador2 = 0
220 | v_x_bolinha = 0
221 | v_y_bolinha = 0
222 |
223 | #VERIFICANDO SE ALGUÉM FEZ UM PONTO
224 | if contou_ponto:
225 | contou_ponto = False
226 | pontos = pts_jogador1+pts_jogador2
227 |
228 | #VERIFICANDO SE DEVE TROCAR A POSIÇÃO DO SAQUE A CADA DOIS PONTOS ANTES DO 10 a 10
229 | if pontos < 20:
230 | if pontos%2 == 0:
231 | if posicao_seta == [850, 15]:
232 | posicao_seta = [850, 55]
233 | else:
234 | posicao_seta = [850, 15]
235 |
236 | if posicao_seta == [850, 15]:
237 | x_bola = 92
238 | y_bola = 359
239 | else:
240 | x_bola = 1005
241 | y_bola = 359
242 |
243 | #VERIFICANDO SE DEVE TROCAR A POSIÇÃO DO SAQUE A PARTIR DO 10 a 10
244 | else:
245 | if posicao_seta == [850, 15]:
246 | posicao_seta = [850, 55]
247 | x_bola = 1005
248 | y_bola = 359
249 | else:
250 | posicao_seta = [850, 15]
251 | x_bola = 92
252 | y_bola = 359
253 |
254 | #VERIFICANDO SE UM DOS DOIS JOGADORES ALCANÇOU 4 SETS
255 | if sets_jogador1 == 4 or sets_jogador2 == 4:
256 | if sets_jogador1 == 4:
257 | vencedor = "O Jogador A venceu a partida!"
258 | else:
259 | vencedor = "O Jogador B venceu a partida!"
260 |
261 | exibirVencedor = fonteAviso.render(vencedor, True, const.cor_vermelha)
262 | const.tela.blit(exibirVencedor, (200, 160))
263 | som_aplausos.play()
264 |
265 | #ATUALIZANDO A POSIÇÃO DOS ELEMENTOS DO JOGO
266 | const.tela.blit(raquete1, (x_rqt1, y_rqt1))
267 | const.tela.blit(raquete2, (x_rqt2, y_rqt2))
268 | const.tela.blit(bola, (x_bola, y_bola))
269 | const.tela.blit(imagem_seta, posicao_seta)
270 |
271 | #EXIBINDO A PONTUAÇÃO NA TELA
272 | nome_jogador1 = fonteTexto.render("Jogador A", True, const.cor_da_borda)
273 | nome_jogador2 = fonteTexto.render("Jogador B", True, const.cor_da_borda)
274 |
275 | pontuacao1_set = "%d" %(sets_jogador1)
276 | pontuacao2_set = "%d" %(sets_jogador2)
277 |
278 | pontuacao1 = "%d" %(pts_jogador1)
279 | pontuacao2 = "%d" %(pts_jogador2)
280 |
281 | pts_set_j1 = fonteNumero.render(pontuacao1_set, True, const.cor_preta)
282 | pts_set_j2 = fonteNumero.render(pontuacao2_set, True, const.cor_preta)
283 |
284 | p1_formatado = fonteNumero.render(pontuacao1, True, const.cor_preta)
285 | p2_formatado = fonteNumero.render(pontuacao2, True, const.cor_preta)
286 |
287 | const.tela.blit(nome_jogador1, (900, 19))
288 | const.tela.blit(nome_jogador2, (900, 55))
289 | const.tela.blit(pts_set_j1, (1022, 17))
290 | const.tela.blit(pts_set_j2, (1022, 53))
291 | const.tela.blit(p1_formatado, (1072, 17))
292 | const.tela.blit(p2_formatado, (1072, 53))
293 |
294 | pygame.display.flip()
295 |
296 | if atrasar_saque:
297 | sleep(1.2)
298 | atrasar_saque = False
299 |
300 | if acabou_set:
301 | sleep(5)
302 | acabou_set = False
303 |
304 | if vencedor != "":
305 | sleep(10)
306 | tela_menu.exibir_tela_menu()
307 |
--------------------------------------------------------------------------------
/tela_regras.py:
--------------------------------------------------------------------------------
1 | import pygame, tela_menu
2 | import constantes as const
3 | from sys import exit
4 | from pygame.locals import *
5 | from time import sleep
6 |
7 | def exibir_tela_regras():
8 |
9 | pygame.init()
10 |
11 | const.tela
12 |
13 | regra1 = pygame.image.load(const.img_regra1)
14 | regra2 = pygame.image.load(const.img_regra2)
15 | regra3 = pygame.image.load(const.img_regra3)
16 |
17 | regra_atual = regra1
18 |
19 | som_seta = pygame.mixer.Sound('sons/som_seta.ogg')
20 |
21 | while True:
22 | const.relogio.tick(const.fps)
23 | for event in pygame.event.get():
24 | if event.type == QUIT:
25 | pygame.quit()
26 | exit()
27 |
28 | tecla = pygame.key.get_pressed()
29 |
30 | #VERIFICANDO SE DEVE MUDAR A TELA DE REGRA
31 | if regra_atual == regra2 and tecla[K_RIGHT]:
32 | regra_atual = regra3
33 |
34 | if regra_atual == regra1 and tecla[K_LEFT] or tecla[K_ESCAPE]:
35 | tela_menu.exibir_tela_menu()
36 |
37 | if regra_atual == regra1 and tecla[K_RIGHT]:
38 | regra_atual = regra2
39 |
40 | if regra_atual == regra2 and tecla[K_LEFT]:
41 | regra_atual = regra1
42 |
43 | if regra_atual == regra3 and tecla[K_LEFT]:
44 | regra_atual = regra2
45 |
46 | const.tela.blit(regra_atual, (0, 0))
47 |
48 | pygame.display.flip()
49 |
50 | #ADICIONANDO UM PEQUENO DELAY AO MUDAR DE TELA
51 | if tecla[K_LEFT] or tecla[K_RIGHT]:
52 | som_seta.play()
53 | sleep(0.25)
--------------------------------------------------------------------------------
/tela_treinamento.py:
--------------------------------------------------------------------------------
1 | import pygame, tela_menu
2 | import constantes as const
3 | from pygame.locals import *
4 | from sys import exit
5 | from raquete import *
6 | from bola import *
7 | from random import randint
8 | from time import sleep
9 |
10 | def exibir_tela_treinamento():
11 |
12 | controlar_saque = True
13 | atrasar_saque = False
14 | direita = False
15 | esquerda = False
16 | v_x_bolinha = 0
17 | v_y_bolinha = 0
18 |
19 | pygame.init()
20 |
21 | const.tela
22 |
23 | #DEFININDO A FONTE USADA PARA EXIBIR O PLACAR
24 | fonteTexto = pygame.font.SysFont(const.fonte, 18, True)
25 | fonteNumero = pygame.font.SysFont(const.fonte, 25, True)
26 | fonteAviso = pygame.font.SysFont(const.fonte, 45, True)
27 |
28 | imagem_seta = pygame.image.load(const.img_seta_direita)
29 | imagem_seta = pygame.transform.scale(imagem_seta, (32, 32))
30 | posicao_seta = [850, 15]
31 |
32 | bola = pygame.image.load(const.img_bolinha)
33 | x_bola = 92
34 | y_bola = 359
35 |
36 | raquete1 = pygame.image.load(const.img_raquete1)
37 | x_rqt1 = 15
38 | y_rqt1 = 330
39 |
40 | #CRIAÇÃO DE MÁSCARAS PARA VERIFICAR COLISÕES ENTRE AS IMAGENS
41 | mascara_bola = pygame.mask.from_surface(bola)
42 | mascara_rqt1 = pygame.mask.from_surface(raquete1)
43 |
44 | som_raquete = pygame.mixer.Sound('sons/som_raquete.ogg')
45 | som_mesa = pygame.mixer.Sound('sons/som_mesa.ogg')
46 |
47 | while True:
48 | const.relogio.tick(85)
49 |
50 | for event in pygame.event.get():
51 | if event.type == QUIT:
52 | pygame.quit()
53 | exit()
54 |
55 | #DESENHANDO A REGIÃO DO PLANO DE FUNDO, PLACAR E MESA
56 | const.tela.fill(const.plano_de_fundo_partida)
57 | pygame.draw.rect(const.tela, const.cor_verde, (0, 0, const.largura, 120))
58 | pygame.draw.rect(const.tela, const.cor_cinza, (890, 15, 175, 70))
59 | pygame.draw.rect(const.tela, const.cor_da_borda, (1015, 15, 100, 70))
60 | pygame.draw.line(const.tela, const.cor_da_borda, (890, 50), (1035, 50), 1)
61 | pygame.draw.line(const.tela, const.cor_cinza, (1015, 50), (1114, 50), 1)
62 | pygame.draw.line(const.tela, const.cor_cinza, (1065, 15), (1065, 85), 1)
63 | pygame.draw.rect(const.tela, const.cor_da_mesa, (100, 120, 920, 500))
64 |
65 | #DESENHANDO AS BORDAS ESQUERDA E DIREITA DA MESA
66 | pygame.draw.line(const.tela, const.cor_da_borda, (104, 120), (104, 619), 10)
67 | pygame.draw.line(const.tela, const.cor_da_borda, (1014, 120), (1014, 619), 10)
68 |
69 | #DESENHANDO AS BORDAS SUPERIOR E INFERIOR DA MESA
70 | pygame.draw.line(const.tela, const.cor_da_borda, (100, 124), (1019, 124), 10)
71 | pygame.draw.line(const.tela, const.cor_da_borda, (100, 614), (1019, 614), 10)
72 |
73 | #DESENHANDO A COR_DA_REDE E LINHA DIVISÓRIA DA MESA
74 | pygame.draw.line(const.tela, const.cor_da_rede, (559, 124), (559, 614), 10)
75 | pygame.draw.aaline(const.tela, const.cor_da_rede, (100, 370), (1019, 370))
76 |
77 | tecla = pygame.key.get_pressed()
78 |
79 | if tecla[K_ESCAPE]:
80 | tela_menu.exibir_tela_menu()
81 |
82 | #AÇÕES DO JOGADOR
83 | if tecla[K_w]:
84 | y_rqt1 = R_praCima(y_rqt1, 120)
85 | if tecla[K_a]:
86 | x_rqt1 = R_praEsquerda(x_rqt1, 0)
87 | if tecla[K_s]:
88 | y_rqt1 = R_praBaixo(y_rqt1, 530)
89 | if tecla[K_d]:
90 | x_rqt1 = R_praDireita(x_rqt1, 240)
91 |
92 | sobreposicao1 = (x_bola - x_rqt1, y_bola - y_rqt1)
93 |
94 | colisao1 = mascara_rqt1.overlap(mascara_bola, sobreposicao1)
95 |
96 | if controlar_saque == True and not colisao1:
97 | if tecla[K_t]:
98 | y_bola = B_praCima(y_bola, 130)
99 | if tecla[K_g]:
100 | y_bola = B_praBaixo(y_bola, 585)
101 |
102 | if colisao1:
103 | som_raquete.play()
104 | controlar_saque = False
105 |
106 | v_x_bolinha = randint(7, 9)
107 | v_y_bolinha = randint(-6, 6)
108 |
109 | if colisao1:
110 | direita = True
111 | esquerda = False
112 |
113 | if x_bola > 985:
114 | som_mesa.play()
115 | direita = False
116 | esquerda = True
117 |
118 | if direita:
119 | x_bola += v_x_bolinha
120 | if esquerda:
121 | x_bola -= v_x_bolinha
122 |
123 | y_bola += v_y_bolinha
124 |
125 | #VERIFICANDO SE A BOLINHA PASSOU DOS LIMITES DA TELA
126 | if x_bola < -32:
127 | controlar_saque = True
128 | atrasar_saque = True
129 | direita = False
130 | esquerda = False
131 |
132 | x_rqt1 = 15
133 | y_rqt1 = 330
134 |
135 | v_x_bolinha = 0
136 | v_y_bolinha = 0
137 |
138 | x_bola = 92
139 | y_bola = 359
140 |
141 | #VERIFICANDO SE A BOLINHA ALCANÇOU AS BORDAS SUPERIOR E INFERIOR DA MESA
142 | if(y_bola < 130):
143 | som_mesa.play()
144 | y_bola = 130
145 | v_y_bolinha = -v_y_bolinha
146 |
147 | if(y_bola > 585):
148 | som_mesa.play()
149 | y_bola = 585
150 | v_y_bolinha = -v_y_bolinha
151 |
152 | #ATUALIZANDO A POSIÇÃO DOS ELEMENTOS DO JOGO
153 | const.tela.blit(raquete1, (x_rqt1, y_rqt1))
154 | const.tela.blit(bola, (x_bola, y_bola))
155 | const.tela.blit(imagem_seta, posicao_seta)
156 |
157 | #EXIBINDO A PONTUAÇÃO NA TELA
158 | nome_jogador1 = fonteTexto.render("Jogador A", True, const.cor_da_borda)
159 | nome_jogador2 = fonteTexto.render("Jogador B", True, const.cor_da_borda)
160 |
161 | pts_set_j1 = fonteNumero.render("0", True, const.cor_preta)
162 | pts_set_j2 = fonteNumero.render("0", True, const.cor_preta)
163 |
164 | p1_formatado = fonteNumero.render("0", True, const.cor_preta)
165 | p2_formatado = fonteNumero.render("0", True, const.cor_preta)
166 |
167 | const.tela.blit(nome_jogador1, (900, 19))
168 | const.tela.blit(nome_jogador2, (900, 55))
169 | const.tela.blit(pts_set_j1, (1022, 17))
170 | const.tela.blit(pts_set_j2, (1022, 53))
171 | const.tela.blit(p1_formatado, (1072, 17))
172 | const.tela.blit(p2_formatado, (1072, 53))
173 |
174 | pygame.display.flip()
175 |
176 | if atrasar_saque:
177 | sleep(0.5)
178 | atrasar_saque = False
--------------------------------------------------------------------------------