Added background music.
This commit is contained in:
Binary file not shown.
@@ -48,6 +48,15 @@ LEVEL_UP_SOUND = load_sound("audio_levelup.wav")
|
|||||||
ENEMY_DEATH_SOUND = load_sound("audio_enemydeath.wav")
|
ENEMY_DEATH_SOUND = load_sound("audio_enemydeath.wav")
|
||||||
EXPLOSION_SOUND = load_sound("explosion_sound.wav")
|
EXPLOSION_SOUND = load_sound("explosion_sound.wav")
|
||||||
|
|
||||||
|
# Load background music (pygame.mixer.music)
|
||||||
|
if os.path.exists("audio_music.mp3"):
|
||||||
|
try:
|
||||||
|
pygame.mixer.music.load("audio_music.mp3")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error loading background music: {e}")
|
||||||
|
else:
|
||||||
|
print("Warning: audio_music.mp3 not found. Background music disabled.")
|
||||||
|
|
||||||
# Set font for score
|
# Set font for score
|
||||||
font = pygame.font.SysFont(None, 30)
|
font = pygame.font.SysFont(None, 30)
|
||||||
|
|
||||||
@@ -278,6 +287,13 @@ def game():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Rumble error: {e}")
|
print(f"Rumble error: {e}")
|
||||||
|
|
||||||
|
# Start background music looping infinitely
|
||||||
|
if pygame.mixer.music.get_busy() == False:
|
||||||
|
try:
|
||||||
|
pygame.mixer.music.play(-1) # -1 means loop indefinitely
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to play background music: {e}")
|
||||||
|
|
||||||
if GO_SOUND:
|
if GO_SOUND:
|
||||||
GO_SOUND.play()
|
GO_SOUND.play()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user