diff --git a/assets/story/directory_search/heart.png b/assets/story/directory_search/heart.png new file mode 100644 index 0000000..c906213 Binary files /dev/null and b/assets/story/directory_search/heart.png differ diff --git a/src/scenes/story/directory_search.py b/src/scenes/story/directory_search.py index aaec53a..efde46b 100644 --- a/src/scenes/story/directory_search.py +++ b/src/scenes/story/directory_search.py @@ -9,7 +9,7 @@ from engine.math import Vec2 from plugins import assets as plugin_assets, render, smooth from plugins.animation import Animation from plugins.coroutine import Coroutine, wait -from plugins.click import Clicked +from plugins.click import Clickable, Clicked from plugins.inputs import Held, MousePosition from plugins.assets import Assets from plugins.render import Sprite @@ -52,12 +52,6 @@ class SearchedDirectoryAlert: """ -class SearchedDirectoryAlertPosition(Vec2): - """ - Composant marquant une entité comme etant la position d'un dossier dans la recherche plus tard. - """ - - class DirectoryName: """ Composant marquant une entité comme étant le nom d'un dossier. @@ -174,91 +168,35 @@ def __initialize(world: World): # Lancement de la boucle de jeu world.new_entity().set(Coroutine(__game_loop(world))) + # Code cool + world.new_entity().set(Coroutine(__lamour_et_le_bonheur(world))) + def __game_loop(world: World): """ La boucle principale de la scène """ - yield wait(5.0) # On attend 5 secondes le temps de mettre le joueur dans le jeu - for _ in range(5): # On fait 5 dossiers (niveau facile) - __spawn_search_alert(world, 5) # On fait 5 alertes de recherche + yield wait(5.0) + for i in range(10): + if i % 2 == 1: + __block_directory(world) + __spawn_search_alerts(world, int(i / 1.5) + 1) + yield wait(5.0 - (i * 0.4)) + __spawn_search_directory(world) yield wait(5.0) - __spawn_search_directory( - world - ) # On fait apparaître le dossier en cours de recherche - __delete_search_alert(world) # On supprime les alertes - yield wait(5.0) - __delete_search_directory(world) # On supprime le dossier en cours de recherche - yield wait(1.0) + print("BRABO BG !") -def __delete_search_directory(world: World): +def __spawn_search_alerts(world: World, nb_alerts: int): """ - Supprime le dossier en cours de recherche - """ - for entity in world.query( - Directory, SearchingDirectory - ): # Pour tous les dossiers recherchés et les remet à leur état de base - del entity[SearchingDirectory] - del entity[Animation] - - -def __spawn_search_directory(world: World): - """ - Fait apparaître le dossier en cours de recherche - """ - for search_alert in world.query( - SearchedDirectoryAlert, SearchedDirectoryAlertPosition - ): - for entity in world.query(Directory, DirectoryPosition): - if ( - entity[DirectoryPosition] - == search_alert[SearchedDirectoryAlertPosition] - ): # Si le dossier va être recherché - if DefenderDirectory in entity: # Si le dossier est un défenseur - # On joue une animation d'échec - entity.set( - SearchingDirectory(), - Animation("search_directory_failed", callback=__game_over), - ) - break - # On joue l'animation de recherche - entity.set(SearchingDirectory(), Animation("search_directory")) - break - - -def __game_over(world: World, _entity: Entity): - """ - Fonction lancée quand on perd le jeu - """ - world[CurrentScene] = SCENE # On relance le jeu - - -def __delete_search_alert(world: World): - """ - Supprime les alertes de recherche - """ - for search_alert in world.query( - SearchedDirectoryAlert, SearchedDirectoryAlertPosition - ): - # On joue l'animation de suppression - search_alert[Animation] = Animation( - "search_alert/despawn", callback=lambda _, entity: entity.destroy() - ) - - -def __spawn_search_alert(world: World, nb_alerts: int): - """ - Spawn une alerte de recherche + Spawn les alertes de recherche """ entities = world.query(Directory, DirectoryPosition, without=[BlockedDirectory]) - - for entity in random.sample( - list(entities), nb_alerts - ): # On tire aléatoirement des dossiers - # On crée l'alerte + entities.difference_update(world.query(DefenderDirectory)) + for entity in random.sample(list(entities), nb_alerts - 1) + list( + world.query(DefenderDirectory) + ): position = entity[DirectoryPosition] - # On crée l'entité de l'alerte world.new_entity().set( Animation("search_alert/spawn"), Sprite( @@ -268,10 +206,75 @@ def __spawn_search_alert(world: World, nb_alerts: int): order=2, ), SearchedDirectoryAlert(), - SearchedDirectoryAlertPosition(position), + DirectoryPosition(position), ) +def __block_directory(world: World): + """ + Bloque un dossier. + """ + entity = random.choice( + list(world.query(Directory, without=(BlockedDirectory, DefenderDirectory))) + ) + entity.set(BlockedDirectory(), Animation("directory_to_blocked")) + + +def __spawn_search_directory(world: World): + """ + Fait apparaître le dossier en cours de recherche + """ + for search_alert in world.query(SearchedDirectoryAlert, DirectoryPosition): + # On joue l'animation de suppression + search_alert[Animation] = Animation( + "search_alert/despawn", callback=lambda _, entity: entity.destroy() + ) + + for search_alert in world.query(SearchedDirectoryAlert, DirectoryPosition): + for entity in world.query(Directory, DirectoryPosition): + if entity[DirectoryPosition] == search_alert[DirectoryPosition]: + if DefenderDirectory in entity: + # On joue une animation d'échec + entity.set( + SearchingDirectory(), + Animation( + "search_directory_failed", + callback=lambda world, _: world.new_entity().set( + Sprite( + world[Assets].get_texture("restart"), + Vec2(render.WIDTH / 2, 900), + 10, + origin=Vec2(0.5), + ), + Clickable( + lambda world, _: world.set( + CurrentScene(__new_game_scene()) + ) + ), + ), + ), + ) + entity[Sprite].order = 5 + for entity in world.query(Coroutine): # On arrete la boucle de jeu + entity.destroy() + continue + + # On joue l'animation de recherche + entity.set( + SearchingDirectory(), + Animation("search_directory", callback=__stop_search), + ) + break + + +def __stop_search(world: World, entity: Entity): + """ + Change la texture du dossier a la fin de sa recherche. + """ + entity.remove(SearchingDirectory) + entity[Sprite].texture = world[Assets].get_texture("directory") + + def __control_directories(world: World): """ Ce système gère les déplacements de dossiers fais par l'utilisateur. @@ -357,12 +360,63 @@ def __update_graphics(world: World): ) -SCENE = plugin_assets.loading_scene( - Scene( - [__initialize], - [__control_directories, __update_graphics], - [], +def __lamour_et_le_bonheur(world: World): + """ + Une fonction qui créer le bonheur et le amour. + """ + while True: + yield wait(0.5) + # Code lugubre tkt c'est un bon code + i_love = None + my_amor = None + for entity in world.query(Text, DirectoryName): + if entity[Text].text == "Je t'aime": + i_love = entity[DirectoryName].entity[DirectoryPosition] + if entity[Text].text == "Mon Amour": + my_amor = entity[DirectoryName].entity[DirectoryPosition] + if ( + i_love is not None + and my_amor is not None + and i_love + Vec2(1, 0) == my_amor + ): + entity = world.new_entity() + x = random.randint(0, render.WIDTH) + entity.set( + Sprite( + world[Assets].get_texture("heart"), + Vec2(x, -100), + 10, + origin=Vec2(0.5), + ), + smooth.Target(x, render.HEIGHT + 100), + smooth.Speed(1), + Coroutine(__despawn_after(entity)), + ) + + +def __despawn_after(entity: Entity): + """ + Détruit l'entité après 5 secondes. + """ + yield wait(5.0) + entity.destroy() + + +def __new_game_scene() -> Scene: + """ + Créer une nouvelle scène + """ + return ( + Scene( + [__initialize], + [__control_directories, __update_graphics], + [], + ) + + smooth.PLUGIN ) - + smooth.PLUGIN, + + +SCENE = plugin_assets.loading_scene( + __new_game_scene(), "story/directory_search", )