mirror of
https://github.com/apirrone/Open_Duck_Mini_Runtime.git
synced 2025-09-03 03:33:54 +00:00
sounds
This commit is contained in:
parent
1b415c1b68
commit
20f8135415
1 changed files with 0 additions and 9 deletions
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue