diff --git a/assets/textures/blue_directory.png b/assets/textures/blue_directory.png deleted file mode 100644 index 5e871fe..0000000 Binary files a/assets/textures/blue_directory.png and /dev/null differ diff --git a/assets/textures/blue_directory_wd.png b/assets/textures/user_directory.png similarity index 100% rename from assets/textures/blue_directory_wd.png rename to assets/textures/user_directory.png diff --git a/src/scenes/directory_search.py b/src/scenes/directory_search.py index fa1e552..ee77c8f 100644 --- a/src/scenes/directory_search.py +++ b/src/scenes/directory_search.py @@ -3,8 +3,11 @@ Scène du jeu dans lequel on se cache de Edmond dans les dossiers. """ from enum import Enum +import random from engine import ( + Animation, Centered, + Delta, Display, Entity, Hovered, @@ -21,10 +24,10 @@ from engine import ( from plugins import smooth -__LINES = 3 -__COLUMNS = 5 -__WAITING_SPACING = 150 -__SEARCHING_SPACING = 200 +LINES = 3 +COLUMNS = 5 +WAITING_SPACING = 200 +SEARCHING_SPACING = 200 class State(Enum): @@ -32,7 +35,7 @@ class State(Enum): Etat de la scène. """ - WAITING = 0 + MOVING = 0 SEARCHING = 1 @@ -46,6 +49,18 @@ class SelectedDirectory: self.position = start_position +class AttackTimer(float): + """ + Ressource qui stoque un timer pour l'attaque. + """ + + +class AttackSpeed(float): + """ + Ressource qui dit le temps de l'attaque. + """ + + class DirectoryPosition: """ La position d'un dossier dans la grille. @@ -60,6 +75,21 @@ class DirectoryPosition: return self.x == value.x and self.y == value.y return False + def screen_position(self, state: State) -> Vec2: + """ + Calcule la position de l'entité sur l'ecran. + """ + size = Vec2(WAITING_SPACING if state == State.MOVING else SEARCHING_SPACING) + offset = -(size * Vec2(COLUMNS - 1, LINES - 1) / 2) + first_position = Vec2(Display.WIDTH / 2, Display.HEIGHT / 2) + offset + return first_position + Vec2(self.x, self.y) * size + + +class AttackPoint(DirectoryPosition): + """ + Composant qui marque un point d'attaque. + """ + class DirectoryName: """ @@ -70,11 +100,19 @@ class DirectoryName: self.entity = entity +class UserDirectory: + """ + Composant qui marque le dossier que l'utilisateur doit protéger. + """ + + def __initialize_world(world: World): """ Initialise le monde de la scène. """ - world[State] = State.WAITING + world[State] = State.MOVING + world[AttackTimer] = AttackTimer(0.0) + world[AttackSpeed] = AttackSpeed(5.0) names = [ "Classique", "Menteur", @@ -83,7 +121,7 @@ def __initialize_world(world: World): "Je t'aime", "Hello", "Cheval", - "La Mort", + "Defender", "Dansons", "Secrets", "Edmond", @@ -92,17 +130,20 @@ def __initialize_world(world: World): "Films", "Cinéma", ] - for y in range(__LINES): - for x in range(__COLUMNS): + for y in range(LINES): + for x in range(COLUMNS): entity = world.create_entity( Position(0, 0), Order(1), Centered(), Texture("directory.png"), - # HoveredTexture("directory_hover.png"), DirectoryPosition(x, y), ) + if x == 2 and y == 1: + entity[UserDirectory] = UserDirectory() + entity[Texture] = Texture("user_directory.png") + world.create_entity( Position(0, 0), Order(1), @@ -113,10 +154,51 @@ def __initialize_world(world: World): ) +def __attacks(world: World): + """ + Déclenche les attaques de Edmond. + """ + world[AttackTimer] = AttackTimer(world[AttackTimer] + world[Delta]) + timer = world[AttackTimer] + if timer >= world[AttackSpeed] and world[State] == State.MOVING: + world[State] = State.SEARCHING + for entity in world.query(AttackPoint): + position = entity[AttackPoint] + for directory_entity in world.query(DirectoryPosition): + if directory_entity[DirectoryPosition] == position: + directory_entity[Animation] = Animation("search_directory") + del entity[AttackPoint] + del entity[Position] + del entity[Order] + del entity[Centered] + del entity[Texture] + elif timer >= world[AttackSpeed] + 5 and world[State] == State.SEARCHING: + world[State] = State.MOVING + for _ in range(10): + position = AttackPoint( + random.randint(0, COLUMNS - 1), + random.randint(0, LINES - 1), + ) + world.create_entity( + position, + Position(position.screen_position(State.MOVING)), + Order(50), + Centered(), + Texture("attack_point.png"), + ) + world[AttackTimer] = AttackTimer(0.0) + world[AttackSpeed] = AttackSpeed(world[AttackSpeed] * 0.9) + + def __move_directories(world: World): """ Permet de déplacer les dossiers avec la souris. """ + # Si on n'est pas dans le bon state on annule + if world[State] != State.MOVING: + return + + # On met à jour la séléction mouse = world[Mouse] for entity in world.query(Hovered, DirectoryPosition): if mouse.is_button_pressed(1): @@ -151,11 +233,11 @@ def __move_directories(world: World): movements: list[tuple[int, int]] = [] if directory_position.x != 0: movements.append((-1, 0)) - if directory_position.x != __COLUMNS - 1: + if directory_position.x != COLUMNS - 1: movements.append((1, 0)) if directory_position.y != 0: movements.append((0, -1)) - if directory_position.y != __LINES - 1: + if directory_position.y != LINES - 1: movements.append((0, 1)) if len(movements) == 0: return @@ -195,14 +277,7 @@ def __update_positions(world: World): """ for entity in world.query(DirectoryPosition): position = entity[DirectoryPosition] - size = Vec2( - __WAITING_SPACING if world[State] == State.WAITING else __SEARCHING_SPACING - ) - offset = -(size * Vec2(__COLUMNS - 1, __LINES - 1) / 2) - first_position = Vec2(Display.WIDTH / 2, Display.HEIGHT / 2) + offset - entity[smooth.Target] = smooth.Target( - first_position + Vec2(position.x, position.y) * size - ) + entity[smooth.Target] = smooth.Target(position.screen_position(world[State])) entity[Order] = Order(position.y + 1) @@ -219,7 +294,7 @@ def __update_directory_names(world: World): SCENE = ( Scene( [__initialize_world], - [__move_directories, __update_positions], + [__attacks, __move_directories, __update_positions], [], ) + smooth.PLUGIN