Le component Sound peu jouer des son random

This commit is contained in:
CoCo_Sol 2023-10-29 22:06:01 +01:00
parent 31ecb98485
commit 1566c780e2
8 changed files with 10 additions and 3 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -6,6 +6,7 @@ Un moteur de jeu inspiré de bevy.
import json
import math
import os
import random
from typing import Callable, Optional, Sequence, SupportsFloat, TypeVar, Union
from time import time
import pygame
@ -592,6 +593,12 @@ class Sound:
stop_on_remove: bool = False,
) -> None:
self.name = name
if os.path.isdir(f"assets/sounds/{name}"):
list_files = os.listdir(f"assets/sounds/{name}")
random_file = random.choice(list_files)
self.name = f"{name}/{random_file}"
self.volume = volume
self.loop = loop
self.callback = callback

View file

@ -20,12 +20,12 @@ def __update(world: World):
text = entity[Text]
for key in keyboard.pressed:
if key == "backspace":
world.create_entity(Sound("backspace.wav"))
world.create_entity(Sound("click"))
text = text[:-1]
if key.startswith("["): # pavé numerique
key = key[1]
if key in entity[Typing]:
world.create_entity(Sound("click.wav"))
world.create_entity(Sound("click"))
text += key
entity[Text] = Text(text)

View file

@ -36,7 +36,7 @@ def on_click_butons(world: World, entity: Entity, name: str):
"""
Fonction qui s'execute quand on clique sur un bouton.
"""
entity[Sound] = Sound("click.wav")
entity[Sound] = Sound("click")
world[Game].change_scene(name)