Skip to content

Commit e2f1db3

Browse files
committed
pantalla de entrada
1 parent bdc994d commit e2f1db3

File tree

10 files changed

+58
-17
lines changed

10 files changed

+58
-17
lines changed

Images/Intro.png

580 KB
Loading

JuegShooter.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from rock_element import Rocks
55
from pygame.locals import *
66
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
88
from Levels.LVL1 import *
99

1010
# INICIALIZAMOS PYGAME
@@ -14,7 +14,7 @@
1414
SCREEN_WIDTH = 1000
1515
SCREEN_HEIGHT = 600
1616
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
17-
pygame.display.set_caption("Enemy Shooter")
17+
pygame.display.set_caption("Code Defenderdd")
1818

1919
# CREAMOS UNA INSTACIA DE LA CLASE MAINCHAR
2020
player = MainChar(SCREEN_WIDTH / 2 - 50 / 2, SCREEN_HEIGHT / 2 - 100 / 2, 50, 100, "Images\programador.png", 5)
@@ -34,7 +34,10 @@
3434
# SOUNDS
3535
shot_sound = pygame.mixer.Sound("Sounds\shootSound.wav")
3636
lose_sound = pygame.mixer.Sound("Sounds\loseSound.wav")
37+
main_theme = pygame.mixer.Sound("Sounds\main_theme.mp3")
3738
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)
3841

3942
# PAUSA
4043
pause = False
@@ -44,7 +47,6 @@
4447
total_paused_time = 0
4548
flag2 = False
4649

47-
4850
# CREMOS LA LISTA DE PIEDRAS
4951
list_rocks = [
5052
Rocks('Images\\rock.png', 40, 0, 0),
@@ -77,15 +79,20 @@ def create_enemy():
7779
enemy = pygame.Rect(x, y, easy_enemy_width, easy_enemy_height)
7880
enemies.append(enemy)
7981

82+
flag_start = False
8083

8184
# GAME LOOP
8285
running = True
8386
clock = pygame.time.Clock()
84-
85-
8687
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+
8794
current_time = pygame.time.get_ticks() /1000
88-
current_time = int(current_time)
95+
current_time = int(current_time)
8996
for event in pygame.event.get():
9097
if event.type == QUIT:
9198
running = False
@@ -117,9 +124,11 @@ def create_enemy():
117124
paused_time = int(paused_time)
118125
flag2 = True
119126

120-
font = pygame.font.SysFont("microsoftjhengheimicrosoftjhengheiui", 30)
127+
font = pygame.font.SysFont("microsoftjhengheimicrosoftjhengheiui", 60)
121128
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()
123132

124133
# VERIFICAMOS LA PAUSA
125134
if not pause:
@@ -130,7 +139,6 @@ def create_enemy():
130139
total_paused_time = total_paused_time + total_paused_time_actual # ACUMULAMOS EL TIEMPO TOTAL DE PAUSA PARA RESTARSELO AL CRONOMETRO MAIN
131140
elapsed_time = pause_time - total_paused_time # RESTAMOS EL TOTAL DEL TIEMPO DE PAUSA AL RELOJ MAIN
132141
flag2 = False
133-
134142

135143
# MOVIMIENTO DEL JUGADOR
136144
keys = pygame.key.get_pressed()
@@ -156,10 +164,6 @@ def create_enemy():
156164
score = score + 1
157165

158166

159-
# ----- ENEMIGOS ------
160-
for enemy in enemies:
161-
if player_rect.colliderect(enemy):
162-
running = False # Game over if player collides with an enemy
163167
# Move the enemies
164168
for enemy in enemies:
165169
if enemy.x < player.pos_x:
@@ -173,7 +177,6 @@ def create_enemy():
173177

174178

175179
# ----- NIVELES ------
176-
177180
if score == 0:
178181
tutorial(enemies,create_enemy)
179182

@@ -217,6 +220,13 @@ def create_enemy():
217220
if player.pos_x > rock.pos_x:
218221
player.pos_x += player.vel
219222

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+
220230
# DIBUJAMOS AL PERSONAJE PRINCIPAL
221231
image = player.image # Accedemos al atributo imagen
222232
image_rect = image.get_rect() # Obtener el rectángulo de la imagen
@@ -233,7 +243,6 @@ def create_enemy():
233243
easy_enemy_image = pygame.image.load("Images\\sintaxError_image.png")
234244
screen.blit(easy_enemy_image, enemy)
235245

236-
237246
# DIBUJAMOS EL SCORE
238247
draw_score(score,screen)
239248

Levels/LVL1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def tutorial(enemies,create_enemy):
2626
if len(enemies) < 1:
2727
create_enemy()
2828

29+
2930
def lvl_1 (enemies,create_enemy,list_rocks,screen):
3031
if len(list_rocks) < 8:
3132
list_rocks.append(Rocks("Images\\rock.png", 40, 200,250))
@@ -44,7 +45,6 @@ def lvl_3(enemies,create_enemy,list_rocks):
4445
if len(enemies) < 15:
4546
create_enemy()
4647

47-
4848
def lvl_4(enemies,create_enemy,list_rocks):
4949
if len(list_rocks) <= 11:
5050
list_rocks.append(Rocks("Images\\rock.png", 40, 250,300))
1 Byte
Binary file not shown.

Sounds/main_theme.mp3

8.91 MB
Binary file not shown.

__pycache__/bullets.cpython-311.pyc

1 Byte
Binary file not shown.

__pycache__/features.cpython-311.pyc

1.36 KB
Binary file not shown.

__pycache__/player.cpython-311.pyc

1 Byte
Binary file not shown.
1 Byte
Binary file not shown.

features.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
import pygame
2+
from pygame.locals import *
3+
import sys
24

35
def draw_score(score,screen):
46
font = pygame.font.SysFont("microsoftjhengheimicrosoftjhengheiui", 30)
57
score_text = font.render("Score: " + str(score), True, "BLACK")
6-
screen.blit(score_text, (10, 10))
8+
screen.blit(score_text, (10, 10))
9+
10+
def start_game():
11+
while True:
12+
for event in pygame.event.get():
13+
if event.type == KEYDOWN:
14+
if event.key == pygame.K_RETURN:
15+
return True
16+
else:
17+
return False
18+
19+
def end_game(screen):
20+
21+
for event in pygame.event.get(): ##SACAR ESTE WHILE TRUE
22+
if event.type == QUIT:
23+
sys.exit()
24+
if event.type == KEYDOWN:
25+
if event.key == K_s:
26+
nombre = input("INGRESA TU NOMBRE: ")
27+
28+
29+
30+
font = pygame.font.SysFont("microsoftjhengheimicrosoftjhengheiui", 40)
31+
end_text = font.render("YOU LOSE", True, "BLACK")
32+
screen.blit(end_text, (450, 270))
33+
pygame.display.flip()
34+
35+
36+
37+
# intro = pygame.image.load("Images\intro.png")
38+
# screen.blit(intro, (0,0))

0 commit comments

Comments
 (0)