4
4
from rock_element import Rocks
5
5
from pygame .locals import *
6
6
from bullets import move_bullet ,remove_bullet_off_screen ,remove_bullet_when_hit_enemy ,bullet_colision
7
- from features import draw_score
7
+ from features import draw_score , start_game , end_game
8
8
from Levels .LVL1 import *
9
9
10
10
# INICIALIZAMOS PYGAME
14
14
SCREEN_WIDTH = 1000
15
15
SCREEN_HEIGHT = 600
16
16
screen = pygame .display .set_mode ((SCREEN_WIDTH , SCREEN_HEIGHT ))
17
- pygame .display .set_caption ("Enemy Shooter " )
17
+ pygame .display .set_caption ("Code Defenderdd " )
18
18
19
19
# CREAMOS UNA INSTACIA DE LA CLASE MAINCHAR
20
20
player = MainChar (SCREEN_WIDTH / 2 - 50 / 2 , SCREEN_HEIGHT / 2 - 100 / 2 , 50 , 100 , "Images\programador.png" , 5 )
34
34
# SOUNDS
35
35
shot_sound = pygame .mixer .Sound ("Sounds\shootSound.wav" )
36
36
lose_sound = pygame .mixer .Sound ("Sounds\loseSound.wav" )
37
+ main_theme = pygame .mixer .Sound ("Sounds\main_theme.mp3" )
37
38
shot_sound .set_volume (0.1 ) # Establece el volumen del sonido de disparo al 50%
39
+ main_theme .play ()
40
+ main_theme .set_volume (0.05 )
38
41
39
42
# PAUSA
40
43
pause = False
44
47
total_paused_time = 0
45
48
flag2 = False
46
49
47
-
48
50
# CREMOS LA LISTA DE PIEDRAS
49
51
list_rocks = [
50
52
Rocks ('Images\\ rock.png' , 40 , 0 , 0 ),
@@ -77,15 +79,20 @@ def create_enemy():
77
79
enemy = pygame .Rect (x , y , easy_enemy_width , easy_enemy_height )
78
80
enemies .append (enemy )
79
81
82
+ flag_start = False
80
83
81
84
# GAME LOOP
82
85
running = True
83
86
clock = pygame .time .Clock ()
84
-
85
-
86
87
while running :
88
+ while flag_start == False :
89
+ intro = pygame .image .load ("Images\intro.png" )
90
+ screen .blit (intro , (0 ,0 ))
91
+ pygame .display .flip ()
92
+ flag_start = start_game ()
93
+
87
94
current_time = pygame .time .get_ticks () / 1000
88
- current_time = int (current_time )
95
+ current_time = int (current_time )
89
96
for event in pygame .event .get ():
90
97
if event .type == QUIT :
91
98
running = False
@@ -117,9 +124,11 @@ def create_enemy():
117
124
paused_time = int (paused_time )
118
125
flag2 = True
119
126
120
- font = pygame .font .SysFont ("microsoftjhengheimicrosoftjhengheiui" , 30 )
127
+ font = pygame .font .SysFont ("microsoftjhengheimicrosoftjhengheiui" , 60 )
121
128
pause_text = font .render ("PAUSE" , True , "BLACK" )
122
- screen .blit (elapsed_time_text , (10 , 40 ))
129
+ screen .blit (pause_text , (450 , 270 ))
130
+
131
+ pygame .display .flip ()
123
132
124
133
# VERIFICAMOS LA PAUSA
125
134
if not pause :
@@ -130,7 +139,6 @@ def create_enemy():
130
139
total_paused_time = total_paused_time + total_paused_time_actual # ACUMULAMOS EL TIEMPO TOTAL DE PAUSA PARA RESTARSELO AL CRONOMETRO MAIN
131
140
elapsed_time = pause_time - total_paused_time # RESTAMOS EL TOTAL DEL TIEMPO DE PAUSA AL RELOJ MAIN
132
141
flag2 = False
133
-
134
142
135
143
# MOVIMIENTO DEL JUGADOR
136
144
keys = pygame .key .get_pressed ()
@@ -156,10 +164,6 @@ def create_enemy():
156
164
score = score + 1
157
165
158
166
159
- # ----- ENEMIGOS ------
160
- for enemy in enemies :
161
- if player_rect .colliderect (enemy ):
162
- running = False # Game over if player collides with an enemy
163
167
# Move the enemies
164
168
for enemy in enemies :
165
169
if enemy .x < player .pos_x :
@@ -173,7 +177,6 @@ def create_enemy():
173
177
174
178
175
179
# ----- NIVELES ------
176
-
177
180
if score == 0 :
178
181
tutorial (enemies ,create_enemy )
179
182
@@ -217,6 +220,13 @@ def create_enemy():
217
220
if player .pos_x > rock .pos_x :
218
221
player .pos_x += player .vel
219
222
223
+
224
+ # ----- ENEMIGOS ------
225
+ for enemy in enemies :
226
+ if player_rect .colliderect (enemy ):
227
+ while True :
228
+ running = end_game (screen ) # Game over if player collides with an enemy
229
+
220
230
# DIBUJAMOS AL PERSONAJE PRINCIPAL
221
231
image = player .image # Accedemos al atributo imagen
222
232
image_rect = image .get_rect () # Obtener el rectángulo de la imagen
@@ -233,7 +243,6 @@ def create_enemy():
233
243
easy_enemy_image = pygame .image .load ("Images\\ sintaxError_image.png" )
234
244
screen .blit (easy_enemy_image , enemy )
235
245
236
-
237
246
# DIBUJAMOS EL SCORE
238
247
draw_score (score ,screen )
239
248
0 commit comments