From 60787effa298ed2bbb80470bd6745c9f7f9cd0e9 Mon Sep 17 00:00:00 2001 From: Tipragot Date: Sun, 29 Oct 2023 23:40:17 +0100 Subject: [PATCH] Mouvement pendant animations --- .../search_directory_failed/info.json | 8 ++++ src/scenes/directory_search.py | 44 ++++++++++--------- 2 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 assets/textures/animations/search_directory_failed/info.json diff --git a/assets/textures/animations/search_directory_failed/info.json b/assets/textures/animations/search_directory_failed/info.json new file mode 100644 index 0000000..ff880c4 --- /dev/null +++ b/assets/textures/animations/search_directory_failed/info.json @@ -0,0 +1,8 @@ +{ + "offset": { + "x": 8, + "y": -83 + }, + "frame_count": 268, + "fps": 60 +} \ No newline at end of file diff --git a/src/scenes/directory_search.py b/src/scenes/directory_search.py index 1dfb7fb..96916b7 100644 --- a/src/scenes/directory_search.py +++ b/src/scenes/directory_search.py @@ -26,8 +26,7 @@ from plugins import smooth LINES = 3 COLUMNS = 5 -WAITING_SPACING = 200 -SEARCHING_SPACING = 200 +SPACING = 200 class State(Enum): @@ -37,7 +36,7 @@ class State(Enum): MOVING = 0 SEARCHING = 1 - WAITING = 2 + GAME_OVER = 2 class SelectedDirectory: @@ -76,11 +75,11 @@ class DirectoryPosition: return self.x == value.x and self.y == value.y return False - def screen_position(self, state: State) -> Vec2: + def screen_position(self) -> Vec2: """ Calcule la position de l'entité sur l'ecran. """ - size = Vec2(WAITING_SPACING if state == State.MOVING else SEARCHING_SPACING) + size = Vec2(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 @@ -133,12 +132,13 @@ def __initialize_world(world: World): ] for y in range(LINES): for x in range(COLUMNS): + position = DirectoryPosition(x, y) entity = world.create_entity( - Position(0, 0), + Position(position.screen_position()), Order(1), Centered(), Texture("directory.png"), - DirectoryPosition(x, y), + position, ) if x == 2 and y == 1: @@ -162,24 +162,24 @@ def __attacks(world: World): world[AttackTimer] = AttackTimer(world[AttackTimer] + world[Delta]) timer = world[AttackTimer] if timer >= world[AttackSpeed] and world[State] == State.MOVING: - entities = world.query(AttackPoint) - if len(entities) > 0: - world[State] = State.SEARCHING - else: - world[State] = State.WAITING - for entity in entities: + 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") + if UserDirectory in directory_entity: + directory_entity[Animation] = Animation( + "search_directory_failed" + ) + world[State] = State.GAME_OVER + else: + 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] + 4.5 and world[State] == State.SEARCHING: - world[State] = State.WAITING - elif timer >= world[AttackSpeed] + 7 and world[State] == State.WAITING: world[State] = State.MOVING for _ in range(10): position = AttackPoint( @@ -188,7 +188,7 @@ def __attacks(world: World): ) world.create_entity( position, - Position(position.screen_position(State.MOVING)), + Position(position.screen_position()), Order(50), Centered(), Texture("attack_point.png"), @@ -202,7 +202,7 @@ 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.SEARCHING: + if world[State] == State.GAME_OVER: return # On met à jour la séléction @@ -253,8 +253,12 @@ def __move_directories(world: World): if movement not in movements: return + # Si l'entité est animé on annule + if Animation in selected_entity: + return + # On trouve l'autre dossier - for entity in world.query(DirectoryPosition): + for entity in world.query(DirectoryPosition, without=(Animation,)): if entity != selected_entity and entity[ DirectoryPosition ] == DirectoryPosition( @@ -284,7 +288,7 @@ def __update_positions(world: World): """ for entity in world.query(DirectoryPosition): position = entity[DirectoryPosition] - entity[smooth.Target] = smooth.Target(position.screen_position(world[State])) + entity[smooth.Target] = smooth.Target(position.screen_position()) entity[Order] = Order(position.y + 1)