Les sons du jeu classique #43
Binary file not shown.
Binary file not shown.
BIN
assets/sounds/click/click0.wav
Normal file
BIN
assets/sounds/click/click0.wav
Normal file
Binary file not shown.
BIN
assets/sounds/click/click1.wav
Normal file
BIN
assets/sounds/click/click1.wav
Normal file
Binary file not shown.
BIN
assets/sounds/click/click2.wav
Normal file
BIN
assets/sounds/click/click2.wav
Normal file
Binary file not shown.
|
@ -6,6 +6,7 @@ Un moteur de jeu inspiré de bevy.
|
||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
from typing import Callable, Optional, Sequence, SupportsFloat, TypeVar, Union
|
from typing import Callable, Optional, Sequence, SupportsFloat, TypeVar, Union
|
||||||
from time import time
|
from time import time
|
||||||
import pygame
|
import pygame
|
||||||
|
@ -592,6 +593,12 @@ class Sound:
|
||||||
stop_on_remove: bool = False,
|
stop_on_remove: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.name = name
|
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.volume = volume
|
||||||
self.loop = loop
|
self.loop = loop
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
|
|
|
@ -20,12 +20,12 @@ def __update(world: World):
|
||||||
text = entity[Text]
|
text = entity[Text]
|
||||||
for key in keyboard.pressed:
|
for key in keyboard.pressed:
|
||||||
if key == "backspace":
|
if key == "backspace":
|
||||||
world.create_entity(Sound("backspace.wav"))
|
world.create_entity(Sound("click"))
|
||||||
text = text[:-1]
|
text = text[:-1]
|
||||||
if key.startswith("["): # pavé numerique
|
if key.startswith("["): # pavé numerique
|
||||||
key = key[1]
|
key = key[1]
|
||||||
if key in entity[Typing]:
|
if key in entity[Typing]:
|
||||||
world.create_entity(Sound("click.wav"))
|
world.create_entity(Sound("click"))
|
||||||
text += key
|
text += key
|
||||||
entity[Text] = Text(text)
|
entity[Text] = Text(text)
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ def on_click_butons(world: World, entity: Entity, name: str):
|
||||||
"""
|
"""
|
||||||
Fonction qui s'execute quand on clique sur un bouton.
|
Fonction qui s'execute quand on clique sur un bouton.
|
||||||
"""
|
"""
|
||||||
entity[Sound] = Sound("click.wav")
|
entity[Sound] = Sound("click")
|
||||||
world[Game].change_scene(name)
|
world[Game].change_scene(name)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue