Added background music.

This commit is contained in:
justin committed 2025-07-14 09:59:08 -07:00
1 parent d0d70390cf
commit ca24f706c1
3 files changed
+17

No files matched your search

Binary file not shown.
Binary file not shown.
+17
View File
@@ -3,8 +3,14 @@ import random
import sys import sys
pygame.init() pygame.init()
pygame.mixer.init()
pygame.joystick.init() pygame.joystick.init()
# Load and play background music
pygame.mixer.music.load("audio_music.mp3")
pygame.mixer.music.set_volume(0.5)
pygame.mixer.music.play(-1) # Loop forever
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
pygame.mouse.set_visible(False) pygame.mouse.set_visible(False)
info = pygame.display.Info() info = pygame.display.Info()
@@ -31,6 +37,8 @@ for i in [1, 2, 4, 5]:
wasabi_img = pygame.image.load("sushi3.png").convert_alpha() wasabi_img = pygame.image.load("sushi3.png").convert_alpha()
wasabi_img = pygame.transform.smoothscale(wasabi_img, SUSHI_SIZE) wasabi_img = pygame.transform.smoothscale(wasabi_img, SUSHI_SIZE)
chomp_sound = pygame.mixer.Sound("audio_chomp.mp3")
joystick = None joystick = None
if pygame.joystick.get_count() > 0: if pygame.joystick.get_count() > 0:
joystick = pygame.joystick.Joystick(0) joystick = pygame.joystick.Joystick(0)
@@ -125,6 +133,10 @@ while True:
if event.key == pygame.K_ESCAPE: if event.key == pygame.K_ESCAPE:
if not exploding and not game_over: if not exploding and not game_over:
paused = not paused paused = not paused
if paused:
pygame.mixer.music.pause()
else:
pygame.mixer.music.unpause()
elif event.key == pygame.K_q: elif event.key == pygame.K_q:
pygame.quit() pygame.quit()
sys.exit() sys.exit()
@@ -134,6 +146,10 @@ while True:
if event.button == 7 or event.button == 6: if event.button == 7 or event.button == 6:
if not exploding and not game_over: if not exploding and not game_over:
paused = not paused paused = not paused
if paused:
pygame.mixer.music.pause()
else:
pygame.mixer.music.unpause()
elif paused and event.button == 2: elif paused and event.button == 2:
pygame.quit() pygame.quit()
sys.exit() sys.exit()
@@ -196,6 +212,7 @@ while True:
explode_start = None explode_start = None
else: else:
score += 1 score += 1
chomp_sound.play()
mid_x = cat_rect.centerx mid_x = cat_rect.centerx
CAT_SIZE[0] += 1 CAT_SIZE[0] += 1
CAT_SIZE[1] += 1 CAT_SIZE[1] += 1