Во время игрового процесса игры должны воспроизводиться звуки при каждом правильном или неправильном нажатии. Отладка говорит, что загружена, но не воспроизводит звук. пожалуйста помоги
SOUNDS_METAL = ["assets/sounds/metal_1.ogg",
"assets/sounds/metal_2.ogg"]
SOUNDS_GLASS = ["assets/sounds/glass_1.ogg",
"assets/sounds/glass_2.ogg"]
SOUNDS_PLASTIC = ["assets/sounds/plastic_1.ogg",
"assets/sounds/plastic_2.ogg"]
SOUNDS_PAPER = ["assets/sounds/paper_1.ogg",
"assets/sounds/paper_2.ogg"]
SOUNDS_FX = ["assets/sounds/fx_pop.ogg",
"assets/sounds/fx_error.ogg"]
SOUNDS = [SOUNDS_METAL, SOUNDS_GLASS, SOUNDS_PLASTIC, SOUNDS_PAPER, SOUNDS_FX]
.
.
.
def collision_detector(mouse_pos, target, points, bin_type):
"""checkt wether or not the click is inside the target area"""
if target[0][0] < mouse_pos[0] < target[0][1]:
if target[1][0] < mouse_pos[1] < target[1][1]:
debuginfo("CORRECT HIT")
points += 1
debuginfo(f"POINTS: {points}")
sound_effectplayer(bin_type)
main(points)
.
.
.
def new_rubbish_maker():
"""creates the ryubbish object"""
global MAIN_RUBBISH
MAIN_RUBBISH = random.choice(ALL_RUBBISH)
sound_effectplayer("new_item")
def sound_effectplayer(object_type):
"""plays the sound effects"""
global sound_effect
debuginfo(f"MUSIC OBJECT TYPE: {object_type}")
if object_type == "metal":
sound_effect = pygame.mixer.Sound(random.choice(SOUNDS_METAL))
debuginfo(f"EFFECT: {sound_effect}")
elif object_type == "plastic":
sound_effect = pygame.mixer.Sound(random.choice(SOUNDS_PLASTIC))
debuginfo(f"EFFECT: {sound_effect}")
elif object_type == "paper":
sound_effect = pygame.mixer.Sound(random.choice(SOUNDS_PLASTIC))
debuginfo(f"EFFECT: {sound_effect}")
elif object_type == "glass":
sound_effect = pygame.mixer.Sound(random.choice(SOUNDS_GLASS))
debuginfo(f"EFFECT: {sound_effect}")
elif object_type == "bad":
sound_effect = pygame.mixer.Sound(SOUNDS_FX[1])
debuginfo(f"EFFECT: {sound_effect}")
elif object_type == "new_item":
sound_effect = pygame.mixer.Sound(SOUNDS_FX[0])
sound_effect.play()
полный код: https://gitlab.com/Gote/game
Добавьте
pygame.mixer.init()
В самый верхsound_effectplayer
функции, чтобы она выглядела так: