-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.py
More file actions
165 lines (127 loc) · 3.66 KB
/
Copy pathmain.py
File metadata and controls
165 lines (127 loc) · 3.66 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
from sys import exit
from pygame import *
from Background import *
from Gasolina import *
from Hud import *
from Meteoro import *
from Nave import *
from Sabredeluz import *
from Sons import *
from Video import *
# Inicialização do jogo
pygame.mixer.init()
pygame.init()
# Background
background = Background()
# Startar o jogo
startGame = Start()
surface = background.createSurface()
# Video
video = Video()
video.play()
# Sons
sons = Sons()
sons.musica_fundo()
# Nave
nave = Nave()
# Meteoros
meteoro = Meteoro(50)
meteoro2 = Meteoro(70)
meteoro3 = Meteoro(100)
# Gasolina
gasolina = Gasolina()
# Sabre de Luz
sabredeluz = Sabredeluz()
# HUD
hud = Hud()
# Pontuação inicial
pontos = 0
# Posição do spawn da nave
nave.position[0] = startGame.largura / 2
nave.position[1] = startGame.altura - 100
hud.inicio()
# Relogio de tempo
relogio = pygame.time.Clock()
pygame.mixer.music.play(-1)
while True:
# Carregar background
startGame.tela.blit(background.image, (0, 0))
# Carrega os objetos na tela
nave.render(startGame.tela)
meteoro.render(startGame.tela)
meteoro2.render(startGame.tela)
meteoro3.render(startGame.tela)
gasolina.render(startGame.tela)
sabredeluz.render(startGame.tela)
# 110 segundos de tempo ao total
tempo_total = 110
# Tirar 1 segundo a cada segundo
tempo_total -= (pygame.time.get_ticks() / 1000)
# FPS
relogio.tick(60)
# Fazer a gasolina descer
gasolina.moveGasolina()
# Fazer o Sabre descer
sabredeluz.movesabre()
# Fazer o meteoro descer
meteoro.moveMeteoro(1)
meteoro2.moveMeteoro(1.3)
meteoro3.moveMeteoro(1.6)
# Mensagem na tela do tempo
time = f'Tempo: {int(tempo_total)}'
tempo = startGame.fonte.render(time, False, (255, 255, 255))
# Mensagem na tela da pontuação
points = f'Pontuacao: {int(pontos)}'
pontuacao = startGame.fonte.render(points, False, (255, 255, 255))
for event in pygame.event.get():
# Evento de fechar o jogo
if event.type == QUIT:
pygame.quit()
exit()
# Esquerda
if pygame.key.get_pressed()[K_a]:
nave.move(-30)
# Direita
if pygame.key.get_pressed()[K_d]:
nave.move(30)
# Objetos de colisão
colisao_meteoro = [meteoro.object(surface), meteoro2.object(surface), meteoro3.object(surface)]
colisao_gasolina = gasolina.object(surface)
colisao_sabre = sabredeluz.object(surface)
nave_colide = nave.object(surface)
startGame.tela.blit(surface, (0, 0))
if nave_colide.colliderect(colisao_gasolina):
pontos += 500
sons.get_gasolina().play()
gasolina.upVelocidade()
gasolina.reset()
if nave_colide.colliderect(colisao_sabre):
sons.tocar_sabre().play()
if pontos >= 100:
pontos -= 100
sabredeluz.upVelocidade()
sabredeluz.reset()
if nave_colide.collidelistall(colisao_meteoro):
sons.barulho_colisao().play()
# Implementação da lógica da HUD
if hud.start():
gasolina.position()
sabredeluz.reset()
meteoro.resetar()
meteoro2.resetar()
meteoro3.resetar()
if tempo_total <= 0:
pygame.mixer.music.stop()
hud.gameOver(pontos)
break
# Verifica se saiu da tela
gasolina.outWindow()
sabredeluz.outWindow()
meteoro.outWindow()
meteoro2.outWindow()
meteoro3.outWindow()
# Aparecer a pontuação e o tempo na tela
startGame.tela.blit(pontuacao, (startGame.largura - 300, 40))
startGame.tela.blit(tempo, (startGame.largura - 200, 0))
# Atualizar o jogo a cada iteração
pygame.display.flip()