Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self):
self.mp_drawing = mp.solutions.drawing_utils
self.mp_drawing_styles = mp.solutions.drawing_styles

pygame.mixer.init()
pygame.init()
pygame.display.set_caption("Misiles")

Expand All @@ -40,6 +41,14 @@ def initialize(self):
self.player = Player()
self.movement = 0

#Music
#Source background: https://pixabay.com/music/upbeat-space-chillout-14194/
#Source gameover: https://pixabay.com/sound-effects/astronaut-says-game-over-73039/
pygame.mixer.music.load("resources/music/space-chillout.mp3")
pygame.mixer.music.set_volume(0.5)
pygame.mixer.music.play(loops=-1)
pygame.mixer.music.stop()

#Timers
self.enemy_timer = 1000
pygame.time.set_timer(ADD_ENEMY, self.enemy_timer)
Expand Down Expand Up @@ -68,12 +77,16 @@ def update(self, delta_time):
if event.key == K_ESCAPE:
self.running = False

elif event.type == QUIT:
self.running = False

if self.lost or not self.started:
for event in events:
#Cuando perdimos o no hemos empezado, ENTER comienza el juego
if event.type == KEYDOWN and event.key == K_RETURN:
self.initialize()
self.started = True
pygame.mixer.music.play()
else:
#Aumentar la velocidad segun el tiempo qu ehemos durado
globals.game_speed = 1 + ( (pygame.time.get_ticks() - self.start_time) / 1000) * .1
Expand Down Expand Up @@ -102,6 +115,8 @@ def process_collisions(self):
collide = pygame.sprite.spritecollide(self.player, self.enemies, False, pygame.sprite.collide_mask)
if collide:
self.lost = True
pygame.mixer.music.load("resources/music/astronaut-says-game-over.mp3")
pygame.mixer.music.play()

def render(self):
self.screen.fill((0,0,0))
Expand Down Expand Up @@ -162,6 +177,8 @@ def loop(self):
self.render()
self.clock.tick(60)
pygame.quit()
pygame.mixer.music.stop()
pygame.mixer.quit()

def process_camera(self):
image = self.webcam.read()
Expand Down
Binary file added resources/music/astronaut-says-game-over.mp3
Binary file not shown.
Binary file added resources/music/space-chillout.mp3
Binary file not shown.