-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
361 lines (289 loc) · 13.9 KB
/
Copy pathmain.py
File metadata and controls
361 lines (289 loc) · 13.9 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
import pygame
import sys
import classe_italo
import constantes
import classe_tubaroes
import classe_bolha
import classe_peixe
import labirinto
import classe_baiacu
import botoes
import time
from pathlib import Path
# RODE O JOGO AQUI
# Esse documento contém todas as telas utilizadas no nosso projeto, bem como a função do loop principal do jogo
pygame.init()
# ---------------------- CURSOR -------------------------------
imagem_cursor = pygame.image.load(Path('imgs', 'cursor_click.png'))
imagem_cursor = pygame.transform.scale_by(imagem_cursor, 1/2)
cursor_superficie = pygame.Surface(imagem_cursor.get_size(), pygame.SRCALPHA)
cursor_superficie.blit(imagem_cursor, (0, 0))
cursor_click = pygame.cursors.Cursor((0, 0), cursor_superficie)
cursor_padrao = pygame.SYSTEM_CURSOR_ARROW
# --------------------------------------------------------------
# ------------------------- MENU INICIAL --------------------------------
def tela_menuinicial():
screen = pygame.display.set_mode((1075, 614))
imagemfundo_inicial = pygame.image.load(Path('imgs', 'menuinicial.png'))
# Botões da tela de início
botoes_menu = []
botao_jogar = botoes.Botoes(constantes.BOTAO, 'JOGAR', (543, 300))
botao_sair = botoes.Botoes(constantes.BOTAO, 'SAIR', (543, 370))
botoes_menu.append(botao_jogar)
botoes_menu.append(botao_sair)
# Loop da tela de início
while True:
screen.blit(imagemfundo_inicial, (0, 0))
pygame.display.set_caption('Paczinhuu - Menu Inicial')
for botao in botoes_menu:
botoes.Botoes.verificar_hoover(botao, cursor_click, cursor_padrao)
for evento in pygame.event.get():
if evento.type == pygame.QUIT:
pygame.quit()
sys.exit()
if evento.type == pygame.MOUSEBUTTONDOWN:
for botao in botoes_menu:
clicou = botoes.Botoes.verificar_clique(botao, screen)
if clicou == True:
if botao == botao_jogar:
tela_historia()
if botao == botao_sair:
pygame.quit()
sys.exit()
pygame.display.update()
# ------------------------------------------------------------------------
# ----------------------------- HISTÓRIA DO JOGO ---------------------------------
def tela_historia():
screen = pygame.display.set_mode((1075, 614))
imagemfundo_historia = pygame.image.load(Path('imgs', 'historia.png'))
cursor_padrao = pygame.SYSTEM_CURSOR_ARROW
pygame.mouse.set_cursor(cursor_padrao)
# Loop da tela de história
while True:
screen.blit(imagemfundo_historia, (0, 0))
pygame.display.set_caption('Paczinhuu - Instruções')
for evento in pygame.event.get():
if evento.type == pygame.QUIT:
pygame.quit()
sys.exit()
if evento.type == pygame.KEYDOWN:
if evento.key == pygame.K_SPACE:
tela_instrucoes()
pygame.display.update()
# ---------------------------------------------------------------------------------
# -------------------------------- INSTRUÇÕES ---------------------------------
def tela_instrucoes():
screen = pygame.display.set_mode((1075, 614))
imagemfundo_instrucoes = pygame.image.load(Path('imgs', 'instrucoes.png'))
# Loop da tela de instruções
while True:
screen.blit(imagemfundo_instrucoes, (0, 0))
pygame.display.set_caption('Paczinhuu - Instruções')
for evento in pygame.event.get():
if evento.type == pygame.QUIT:
pygame.quit()
sys.exit()
if evento.type == pygame.KEYDOWN:
if evento.key == pygame.K_SPACE:
rodar_jogo()
pygame.display.update()
# -----------------------------------------------------------------------------
# ------------------------------------- VITÓRIA -----------------------------------------
def tela_vitoria():
# Inicialização
screen_vit = pygame.display.set_mode((1075, 614))
imagemfundo_vitoria = pygame.image.load(Path('imgs', 'vitoria.png'))
# Botões da tela de vitória
botoes_vitoria = []
botao_reiniciar = botoes.Botoes(constantes.BOTAO, 'REINICIAR', (393, 400))
botao_menu = botoes.Botoes(constantes.BOTAO, 'MENU', (693, 400))
botoes_vitoria.append(botao_reiniciar)
botoes_vitoria.append(botao_menu)
# Loop da tela de vitória
while True:
screen_vit.blit(imagemfundo_vitoria, (0, 0))
pygame.display.set_caption('Paczinhuu - VITÓRIA!')
for botao in botoes_vitoria:
botoes.Botoes.verificar_hoover(botao, cursor_click, cursor_padrao)
for evento in pygame.event.get():
if evento.type == pygame.QUIT:
pygame.quit()
sys.exit()
if evento.type == pygame.MOUSEBUTTONDOWN:
for botao in botoes_vitoria:
clicou = botoes.Botoes.verificar_clique(botao, constantes.SCREEN)
if clicou == True:
if botao == botao_reiniciar:
rodar_jogo()
if botao == botao_menu:
tela_menuinicial()
pygame.display.update()
# ---------------------------------------------------------------------------------------
# ------------------------------ GAME OVER PADRÃO -----------------------------------
def tela_gameover():
screen = pygame.display.set_mode((1075, 614))
imagemfundo_gameover = pygame.image.load(Path('imgs', 'gameover.png'))
# Botões da tela de game over
botoes_gameover = []
botao_reiniciar = botoes.Botoes(constantes.BOTAO, 'REINICIAR', (393, 400))
botao_menu = botoes.Botoes(constantes.BOTAO, 'MENU', (693, 400))
botoes_gameover.append(botao_reiniciar)
botoes_gameover.append(botao_menu)
# Loop da tela de game over
while True:
screen.blit(imagemfundo_gameover, (0, 0))
pygame.display.set_caption('Paczinhuu - GAME OVER!')
for botao in botoes_gameover:
botoes.Botoes.verificar_hoover(botao, cursor_click, cursor_padrao)
for evento in pygame.event.get():
if evento.type == pygame.QUIT:
pygame.quit()
sys.exit()
if evento.type == pygame.MOUSEBUTTONDOWN:
for botao in botoes_gameover:
clicou = botoes.Botoes.verificar_clique(botao, constantes.SCREEN)
if clicou == True:
if botao == botao_reiniciar:
rodar_jogo()
if botao == botao_menu:
tela_menuinicial()
pygame.display.update()
# ----------------------------------------------------------------------------
# ------------------------------ GAME OVER TEMPO -----------------------------------
def tela_gameover_tempo():
screen = pygame.display.set_mode((1075, 614))
imagemfundo_gameover = pygame.image.load(Path('imgs', 'gameovert.png'))
# Botões da tela de game over
botoes_gameover = []
botao_reiniciar = botoes.Botoes(constantes.BOTAO, 'REINICIAR', (393, 400))
botao_menu = botoes.Botoes(constantes.BOTAO, 'MENU', (693, 400))
botoes_gameover.append(botao_reiniciar)
botoes_gameover.append(botao_menu)
# Loop da tela de game over
while True:
screen.blit(imagemfundo_gameover, (0, 0))
pygame.display.set_caption('Paczinhuu - GAME OVER!')
for botao in botoes_gameover:
botoes.Botoes.verificar_hoover(botao, cursor_click, cursor_padrao)
for evento in pygame.event.get():
if evento.type == pygame.QUIT:
pygame.quit()
sys.exit()
if evento.type == pygame.MOUSEBUTTONDOWN:
for botao in botoes_gameover:
clicou = botoes.Botoes.verificar_clique(botao, constantes.SCREEN)
if clicou == True:
if botao == botao_reiniciar:
rodar_jogo()
if botao == botao_menu:
tela_menuinicial()
pygame.display.update()
# ----------------------------------------------------------------------------
# ------------------------------------------- LOOP DO JOGO --------------------------------------------
def rodar_jogo():
# Tempo total do jogo em segundos
TEMPO_TOTAL = 100
# Tempo contando
tempo = time.time()
# Contador de tempo
contador_tempo = pygame.time.get_ticks()
# Inicialização
screen = pygame.display.set_mode(constantes.SIZE)
pygame.display.set_caption('Paczinhuu')
font = pygame.font.Font('fontegamer.ttf', 25)
posicao_inicial_italo = (517, 380)
posicao_inicial_tubarao1 = (520, 285)
clock = pygame.time.Clock()
running = True
italo = classe_italo.ItaloSena(posicao_inicial_italo)
# Variáveis de contagem
contagem_peixes = 0
contagem_baiacus = 0
# Definição das posições das placas
placa_image = pygame.image.load(Path('imgs', 'placa.png'))
placa_rect1 = placa_image.get_rect(topleft=(10, 10))
placa_rect2 = placa_image.get_rect(topleft=(placa_rect1.right + 10, 10))
placa_rect3 = placa_image.get_rect(topleft=(placa_rect2.right + 10, 10))
placa_rect4 = placa_image.get_rect(topleft=(placa_rect3.right + 10, 10))
# Posicionar os coletáveis
peixes = classe_peixe.Coletavel_peixe([(60, 75), (995, 540)])
bolhas = classe_bolha.Coletavel_bolha(60, 65, peixes, constantes.MAPA)
baiacus = classe_baiacu.Coletavel_baiacu([(987, 60), (53, 530)])
# Objeto dos tubarões (dois ao total)
tubaroes = [classe_tubaroes.Tubaroes(posicao_inicial_tubarao1)]
tubarao_adicionado = False
tempo_inicio = time.time()
tempo_inicial_printar = 100
# Loop principal do jogo
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
mins_total = tempo_inicial_printar / 60
segs_total = tempo_inicial_printar -(60*(mins_total))
tempo_inicial_printar -= 1
screen.blit(constantes.PRAIA, (0, 0))
screen.blit(labirinto.labirinto_imagem, (0,0))
italo.movimentacao()
italo.atualizar_furia()
italo.atualizar_velmaior()
new_position = italo.retornar_posicao()
italo.renderizar()
tempo_atual = time.time()
tempo_passado = tempo_atual - tempo_inicio
if tempo_passado >= 18 and not tubarao_adicionado:
tubaroes.append(classe_tubaroes.Tubaroes((520, 285)))
tubarao_adicionado = True
for tubarao in tubaroes:
tubarao.movimentacao()
if tubarao.checar_colisao_complayer(italo) and not italo.em_furia:
tela_gameover()
elif tubarao.checar_colisao_complayer(italo) and italo.em_furia:
tubarao.resetar_posicao()
tubarao.renderizar(screen)
if tempo >= 18000:
tubarao.renderizar(screen)
bolhas.renderizar(screen)
peixes.renderizar(screen)
baiacus.renderizar(screen)
bolhas.verificar_colisao(new_position)
italo_rect = pygame.Rect(italo.posicao[0], italo.posicao[1], 30, 30)
if peixes.coleta_peixe(italo_rect):
contagem_peixes += 1
italo.iniciar_velmaior()
if baiacus.coleta_baiacu(italo_rect):
contagem_baiacus += 1
italo.iniciar_furia()
# Renderizar as placas
constantes.SCREEN.blit(placa_image, placa_rect1)
constantes.SCREEN.blit(placa_image, placa_rect2)
constantes.SCREEN.blit(placa_image, placa_rect3)
constantes.SCREEN.blit(placa_image, placa_rect4)
tempo_limite_atual = time.time()
contador_tempo += pygame.time.get_ticks()
# Renderizar as contagens dentro das placas
texto_peixes = font.render(f'PEIXES: {contagem_peixes}', True, (0, 0, 0))
texto_bolhas = font.render(f'BOLHAS: {bolhas.qtd_bolhas}', True, (0, 0, 0))
texto_baiacus = font.render(f'BAIACUS: {contagem_baiacus}', True, (0, 0, 0))
printar_tempo = 100 - (tempo_limite_atual - tempo_inicio)
texto_tempo = font.render(f'TEMPO: {printar_tempo:.2f}', True, (0, 0, 0))
# Posicionar os textos dentro das placas
text_rect1 = texto_peixes.get_rect(center=(placa_rect1.centerx, placa_rect1.centery))
text_rect2 = texto_bolhas.get_rect(center=(placa_rect2.centerx, placa_rect2.centery))
text_rect3 = texto_baiacus.get_rect(center=(placa_rect3.centerx, placa_rect3.centery))
text_rect4 = texto_tempo.get_rect(center=(placa_rect4.centerx, placa_rect4.centery))
constantes.SCREEN.blit(texto_peixes, text_rect1)
constantes.SCREEN.blit(texto_bolhas, text_rect2)
constantes.SCREEN.blit(texto_baiacus, text_rect3)
constantes.SCREEN.blit(texto_tempo, text_rect4)
if classe_bolha.Coletavel_bolha.verificar_pegou_bolhas(bolhas) and classe_peixe.Coletavel_peixe.verificar_pegou_peixes(peixes, contagem_peixes) and classe_baiacu.Coletavel_baiacu.verificar_pegou_baiacus(baiacus, contagem_baiacus):
tela_vitoria()
if tempo_limite_atual - tempo_inicio > 100:
tela_gameover_tempo()
pygame.display.flip()
clock.tick(60)
pygame.quit()
sys.exit()
# --------------------------------------------------------------------------------------------------------------------------
# Aqui o jogo é rodado
tela_menuinicial()