Merge branch 'main' into menteur

This commit is contained in:
Tipragot 2023-10-30 01:55:01 +01:00
commit a7f2aa75d2
11 changed files with 30 additions and 3 deletions

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 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

View file

@ -2,7 +2,7 @@
Definit un plugin qui crée un texte avec les touches frappées 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): class Typing(str):
@ -20,10 +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("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"))
text += key text += key
entity[Text] = Text(text) entity[Text] = Text(text)

View file

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