Ajout de son lors de la frappe au clavier

This commit is contained in:
CoCo_Sol 2023-10-29 21:42:16 +01:00
parent 7cc33baf13
commit 31ecb98485
2 changed files with 3 additions and 1 deletions

BIN
assets/sounds/backspace.wav Normal file

Binary file not shown.

View file

@ -2,7 +2,7 @@
Definit un plugin qui crée un texte avec les touches frappées
"""
from engine import Keyboard, Scene, Text, World
from engine import Keyboard, Scene, Sound, Text, World
class Typing(str):
@ -20,10 +20,12 @@ def __update(world: World):
text = entity[Text]
for key in keyboard.pressed:
if key == "backspace":
world.create_entity(Sound("backspace.wav"))
text = text[:-1]
if key.startswith("["): # pavé numerique
key = key[1]
if key in entity[Typing]:
world.create_entity(Sound("click.wav"))
text += key
entity[Text] = Text(text)