Merge branch 'main' into boss-fight
This commit is contained in:
commit
8042a33207
BIN
assets/story/directory_search/play_again.png
Normal file
BIN
assets/story/directory_search/play_again.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
BIN
assets/story/directory_search/play_again_hover.png
Normal file
BIN
assets/story/directory_search/play_again_hover.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
BIN
assets/waiting.mp3
Normal file
BIN
assets/waiting.mp3
Normal file
Binary file not shown.
|
@ -8,6 +8,7 @@ import pygame
|
|||
from engine import CurrentScene, GlobalPlugin, KeepAlive, Scene
|
||||
from engine.ecs import World
|
||||
from plugins import render
|
||||
from plugins.sound import Sound
|
||||
|
||||
|
||||
class Assets(KeepAlive):
|
||||
|
@ -25,6 +26,7 @@ class Assets(KeepAlive):
|
|||
|
||||
# Chragement du son d'erreur
|
||||
self.__error_sound = pygame.mixer.Sound("assets/error.mp3")
|
||||
self.__waiting_sound = pygame.mixer.Sound("assets/waiting.mp3")
|
||||
|
||||
# Chargement des textures de chargement
|
||||
self.__unloaded_texture = pygame.image.load("assets/unloaded.png").convert()
|
||||
|
@ -54,6 +56,13 @@ class Assets(KeepAlive):
|
|||
"""
|
||||
return self.__error_sound
|
||||
|
||||
@property
|
||||
def waiting_sound(self) -> pygame.mixer.Sound:
|
||||
"""
|
||||
Le son de chargement.
|
||||
"""
|
||||
return self.__waiting_sound
|
||||
|
||||
@property
|
||||
def unloaded_texture(self) -> pygame.Surface:
|
||||
"""
|
||||
|
@ -207,6 +216,7 @@ def loading_scene(target: Scene, name: str, clear_cache: bool = True):
|
|||
order=1000000001,
|
||||
area=(0, 0, 0, render.HEIGHT),
|
||||
),
|
||||
Sound(assets.waiting_sound, loop=True, fade_ms=10000),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -10,6 +10,7 @@ from plugins import (
|
|||
display,
|
||||
hover,
|
||||
inputs,
|
||||
multisound,
|
||||
render,
|
||||
sound,
|
||||
text,
|
||||
|
@ -25,6 +26,7 @@ PLUGIN = (
|
|||
+ hover.PLUGIN
|
||||
+ click.PLUGIN
|
||||
+ coroutine.PLUGIN
|
||||
+ multisound.PLUGIN
|
||||
+ sound.PLUGIN
|
||||
+ text.PLUGIN
|
||||
+ animation.PLUGIN
|
||||
|
|
65
src/plugins/multisound.py
Normal file
65
src/plugins/multisound.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
"""
|
||||
Plugin pour les sons multiples.
|
||||
"""
|
||||
|
||||
|
||||
import random
|
||||
from typing import Callable
|
||||
from engine import GlobalPlugin
|
||||
|
||||
from engine.ecs import Entity, World
|
||||
from plugins.assets import Assets
|
||||
from plugins.sound import Sound
|
||||
|
||||
|
||||
class MultiSound:
|
||||
"""
|
||||
Composant qui quand il est ajouté a une entité, il joue un son aléatoire
|
||||
parmis la liste de ses sons, il est ensuite retiré de l'entité.
|
||||
|
||||
Ce composant est fait pour être définis en tant que constante
|
||||
puis utilisé ensuite, pour cela il prend seulement le nom des
|
||||
sons au lieu des sons eux memes. Les sons seront donc récupérés
|
||||
a l'aide de `Assets`.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*sound_names: str,
|
||||
loop: bool = False,
|
||||
volume: float = 1.0,
|
||||
fade_ms: int = 0,
|
||||
callback: Callable[[World, Entity], object] = lambda _w, _e: None,
|
||||
):
|
||||
self.sound_names = sound_names
|
||||
self.loop = loop
|
||||
self.volume = volume
|
||||
self.fade_ms = fade_ms
|
||||
self.callback = callback
|
||||
|
||||
|
||||
def __update_sounds(world: World):
|
||||
"""
|
||||
Met à jour les sons du jeu.
|
||||
"""
|
||||
# Ajout des sons aléatoires
|
||||
assets = world[Assets]
|
||||
for entity in world.query(MultiSound):
|
||||
multi_sound = entity[MultiSound]
|
||||
sound = assets.get_sound(random.choice(multi_sound.sound_names))
|
||||
entity[Sound] = Sound(
|
||||
sound,
|
||||
multi_sound.loop,
|
||||
multi_sound.volume,
|
||||
multi_sound.fade_ms,
|
||||
multi_sound.callback,
|
||||
)
|
||||
del entity[MultiSound]
|
||||
|
||||
|
||||
PLUGIN = GlobalPlugin(
|
||||
[],
|
||||
[],
|
||||
[__update_sounds],
|
||||
[],
|
||||
)
|
|
@ -3,12 +3,10 @@ Un plugin permettant de jouer des sons.
|
|||
"""
|
||||
|
||||
|
||||
import random
|
||||
from typing import Callable
|
||||
import pygame
|
||||
from engine import GlobalPlugin, KeepAlive
|
||||
from engine.ecs import Entity, World
|
||||
from plugins.assets import Assets
|
||||
|
||||
|
||||
class Channels(KeepAlive, dict[Entity, pygame.mixer.Channel]):
|
||||
|
@ -37,32 +35,6 @@ class Sound:
|
|||
self.callback = callback
|
||||
|
||||
|
||||
class MultiSound:
|
||||
"""
|
||||
Composant qui quand il est ajouté a une entité, il joue un son aléatoire
|
||||
parmis la liste de ses sons, il est ensuite retiré de l'entité.
|
||||
|
||||
Ce composant est fait pour être définis en tant que constante
|
||||
puis utilisé ensuite, pour cela il prend seulement le nom des
|
||||
sons au lieu des sons eux memes. Les sons seront donc récupérés
|
||||
a l'aide de `Assets`.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*sound_names: str,
|
||||
loop: bool = False,
|
||||
volume: float = 1.0,
|
||||
fade_ms: int = 0,
|
||||
callback: Callable[[World, Entity], object] = lambda _w, _e: None,
|
||||
):
|
||||
self.sound_names = sound_names
|
||||
self.loop = loop
|
||||
self.volume = volume
|
||||
self.fade_ms = fade_ms
|
||||
self.callback = callback
|
||||
|
||||
|
||||
def __initialize(world: World):
|
||||
"""
|
||||
Ajoute les ressources utiles pour le plugin.
|
||||
|
@ -74,20 +46,6 @@ def __update_sounds(world: World):
|
|||
"""
|
||||
Met à jour les sons du jeu.
|
||||
"""
|
||||
# Ajout des sons aléatoires
|
||||
assets = world[Assets]
|
||||
for entity in world.query(MultiSound):
|
||||
multi_sound = entity[MultiSound]
|
||||
sound = assets.get_sound(random.choice(multi_sound.sound_names))
|
||||
entity[Sound] = Sound(
|
||||
sound,
|
||||
multi_sound.loop,
|
||||
multi_sound.volume,
|
||||
multi_sound.fade_ms,
|
||||
multi_sound.callback,
|
||||
)
|
||||
del entity[MultiSound]
|
||||
|
||||
# Ajout des sons non gérés
|
||||
channels = world[Channels]
|
||||
sound_entities = world.query(Sound)
|
||||
|
|
|
@ -30,9 +30,11 @@ def __update(world: World):
|
|||
writing = entity[Writing]
|
||||
text = entity[Text]
|
||||
for key in pressed:
|
||||
if key == "backspace":
|
||||
if key == "backspace" and text.text != writing.base_text:
|
||||
text.text = text.text[:-1]
|
||||
world.new_entity().set(CLICK_SOUND)
|
||||
if text.text == "":
|
||||
text.text = writing.base_text
|
||||
if key.startswith("["): # pavé numerique
|
||||
key = key[1]
|
||||
if key in writing.accepted_chars and (
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Module contenant toutes les scènes du jeu.
|
||||
"""
|
||||
|
||||
from plugins.sound import MultiSound
|
||||
from plugins.multisound import MultiSound
|
||||
|
||||
|
||||
CLICK_SOUND = MultiSound("click/0", "click/1", "click/2")
|
||||
|
|
|
@ -277,7 +277,7 @@ def __update(world: World):
|
|||
# On verifie le mode de jeu actuel est le mode trichuer
|
||||
if world[GameMode] == GameMode.CHEATER:
|
||||
# on modifie le nombre en ajoutant un nombre de l'intervalle [-3, 3]
|
||||
world[Number] += random.randint(-3, 3)
|
||||
world[Number] += max(0, min(99, random.randint(-3, 3)))
|
||||
|
||||
|
||||
# Definit la Scene "par defaut" qui contient l'entireté des 3 modes en fonction de GameMode
|
||||
|
|
|
@ -13,7 +13,7 @@ from plugins.assets import Assets
|
|||
from plugins.click import Clickable
|
||||
from plugins.hover import HoveredTexture
|
||||
from plugins.render import Sprite
|
||||
from scenes.story import boss_fight
|
||||
from scenes.story import boss_fight, directory_search
|
||||
|
||||
|
||||
def __create_button(world: World, assets: Assets, i: int, name: str):
|
||||
|
@ -48,7 +48,7 @@ def __on_click_butons(world: World, _entity: Entity, name: str):
|
|||
case "tricheur":
|
||||
world[CurrentScene] = base_game.CHEATER
|
||||
case "histoire":
|
||||
world[CurrentScene] = boss_fight.SCENE
|
||||
world[CurrentScene] = directory_search.SCENE
|
||||
case _:
|
||||
pass
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ from plugins import assets as plugin_assets, render, smooth
|
|||
from plugins.animation import Animation
|
||||
from plugins.coroutine import Coroutine, wait
|
||||
from plugins.click import Clickable, Clicked
|
||||
from plugins.hover import HoveredTexture
|
||||
from plugins.inputs import Held, MousePosition
|
||||
from plugins.assets import Assets
|
||||
from plugins.render import Sprite
|
||||
|
@ -241,11 +242,15 @@ def __spawn_search_directory(world: World):
|
|||
"search_directory_failed",
|
||||
callback=lambda world, _: world.new_entity().set(
|
||||
Sprite(
|
||||
world[Assets].get_texture("restart"),
|
||||
Vec2(render.WIDTH / 2, 900),
|
||||
world[Assets].get_texture("play_again"),
|
||||
Vec2(render.WIDTH / 2, 925),
|
||||
10,
|
||||
origin=Vec2(0.5),
|
||||
),
|
||||
HoveredTexture(
|
||||
world[Assets].get_texture("play_again"),
|
||||
world[Assets].get_texture("play_again_hover"),
|
||||
),
|
||||
Clickable(
|
||||
lambda world, _: world.set(
|
||||
CurrentScene(__new_game_scene())
|
||||
|
|
Loading…
Reference in a new issue