This commit is contained in:
apirrone 2025-03-11 10:38:51 +01:00
parent 1b415c1b68
commit 20f8135415

View file

@ -3,14 +3,12 @@ import time
import os
import random
class Sounds:
def __init__(self, volume=1.0, sound_directory="./"):
pygame.mixer.init()
pygame.mixer.music.set_volume(volume)
self.sounds = {}
# Load all .wav files in the directory
for file in os.listdir(sound_directory):
if file.endswith(".wav"):
sound_path = os.path.join(sound_directory, file)
@ -21,9 +19,6 @@ class Sounds:
print(f"Failed to load {file}: {e}")
def play(self, sound_name):
"""
Plays the specified sound if it exists.
"""
if sound_name in self.sounds:
self.sounds[sound_name].play()
print(f"Playing: {sound_name}")
@ -31,10 +26,6 @@ class Sounds:
print(f"Sound '{sound_name}' not found!")
def play_random_sound(self):
"""
Plays the specified sound if it exists.
"""
sound_name = random.choice(list(self.sounds.keys()))
self.sounds[sound_name].play()