Mode menteur #45

Merged
CoCo_Sol merged 10 commits from menteur into main 2023-10-30 00:57:21 +00:00
11 changed files with 30 additions and 3 deletions
Showing only changes of commit a7f2aa75d2 - Show all commits

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
assets/sounds/win_sound.wav Normal file

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

@ -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("click"))
text = text[:-1]
if key.startswith("["): # pavé numerique
key = key[1]
if key in entity[Typing]:
world.create_entity(Sound("click"))
text += key
entity[Text] = Text(text)

View file

@ -9,12 +9,14 @@ from engine import (
Clickable,
Color,
Display,
Entity,
Game,
HoveredTexture,
Keyboard,
Order,
Position,
Scene,
Sound,
Text,
TextSize,
Texture,
@ -113,7 +115,7 @@ def __initialize_world(world: World):
Order(11),
Position(150, 150),
Texture("classique/arrow.png"),
Clickable(lambda world, _: world[Game].change_scene("menu")),
Clickable(on_menu_button),
HoveredTexture("classique/arrow_hover.png"),
)
@ -123,12 +125,22 @@ def __initialize_world(world: World):
world[IsRunning] = IsRunning()
def on_menu_button(world: World, entity: Entity):
"""
Fonction qui s'execute quand on clique sur un bouton.
"""
world[Game].change_scene("menu")
entity[Sound] = Sound("click")
def _update(world: World):
"""
Verifie si le nombre donné est le meme que celui que l'on a choisi.
Boucle du jeu.
"""
world.create_entity(Sound("menu_click.wav"))
# si le jeu s'est arrete.
if IsRunning not in world:
# on relance le jeu.
@ -169,6 +181,12 @@ def end_game(world: World, state: str):
"""
del world[IsRunning] # le jeu est fini.
# On joue le son
if state == "Gagné":
world.create_entity(Sound("win_sound.wav"))
else:
world.create_entity(Sound("lose_sound.wav"))
# On affiche le message de fin.
for entity_text in world.query(TextDialogue):
entity_text[Text] = Text(f"{state} !")

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)