From 62eec447599feffe25fd2c31d1f88cd546bf9548 Mon Sep 17 00:00:00 2001 From: CoCo_Sol Date: Mon, 30 Oct 2023 19:19:21 +0100 Subject: [PATCH] =?UTF-8?q?System=20de=20dossiers=20bloqu=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scenes/directory_search.py | 79 ++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/src/scenes/directory_search.py b/src/scenes/directory_search.py index 4850eb6..05a57af 100644 --- a/src/scenes/directory_search.py +++ b/src/scenes/directory_search.py @@ -241,29 +241,54 @@ def __attacks(world: World): del entity[Order] del entity[Centered] del entity[Texture] + elif timer >= world[AttackSpeed] + 4.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()), - Order(50), - Centered(), - Texture("attack_point.png"), - ) + + # on suprime les dossiers bloqués + for entity in world.query(BlockedDirectory): + del entity[BlockedDirectory] + entity[Texture] = Texture("directory.png") + # On definit les directories comme bloques for _ in range(3): - position = Vec2( - random.randint(0, COLUMNS - 1), - random.randint(0, LINES - 1), - ) - for entity in world.query(DirectoryPosition): - if entity[DirectoryPosition] == position and UserDirectory not in entity: + x = random.randint(0, COLUMNS - 1) + y = random.randint(0, LINES - 1) + + position = DirectoryPosition(x, y) + + for entity in world.query( + DirectoryPosition, Texture, without=[UserDirectory] + ): + if ( + entity[DirectoryPosition].screen_position() + == position.screen_position() + ): entity[BlockedDirectory] = BlockedDirectory() + entity[Texture] = Texture("blocked_directory.png") + for _ in range(10): + x = random.randint(0, COLUMNS - 1) + y = random.randint(0, LINES - 1) + position = AttackPoint(x, y) + + # On verifie que l'entité n'est pas bloquée + is_on_blocked_directory = False + for entity in world.query(BlockedDirectory, DirectoryPosition): + if ( + entity[DirectoryPosition].screen_position() + == position.screen_position() + ): + is_on_blocked_directory = True + break + + if not is_on_blocked_directory: + world.create_entity( + position, + Position(position.screen_position()), + Order(50), + Centered(), + Texture("attack_point.png"), + ) world[AttackTimer] = AttackTimer(0.0) world[AttackSpeed] = AttackSpeed(world[AttackSpeed] * 0.9) @@ -297,6 +322,11 @@ def __move_directories(world: World): del world[SelectedDirectory] return + # On annule si le dossier selectionne est bloqué + if BlockedDirectory in selected_entity: + del world[SelectedDirectory] + return + # On calcule le déplacement de la souris mouse_delta = mouse.position - selected_directory.position @@ -333,11 +363,14 @@ def __move_directories(world: World): # On trouve l'autre dossier for entity in world.query(DirectoryPosition, without=(Animation,)): - if entity != selected_entity and entity[ - DirectoryPosition - ] == DirectoryPosition( - directory_position.x + movement[0], - directory_position.y + movement[1], + if ( + entity != selected_entity + and entity[DirectoryPosition] + == DirectoryPosition( + directory_position.x + movement[0], + directory_position.y + movement[1], + ) + and BlockedDirectory not in entity ): other_directory = entity break