From 8cb5474eb724616704496ad513c44097e8ed8e54 Mon Sep 17 00:00:00 2001 From: Tipragot Date: Sun, 29 Oct 2023 22:49:45 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20du=20syst=C3=A8me=20de=20vagues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/textures/blue_directory.png | Bin 3981 -> 0 bytes ...ue_directory_wd.png => user_directory.png} | Bin src/scenes/directory_search.py | 117 ++++++++++++++---- 3 files changed, 96 insertions(+), 21 deletions(-) delete mode 100644 assets/textures/blue_directory.png rename assets/textures/{blue_directory_wd.png => user_directory.png} (100%) diff --git a/assets/textures/blue_directory.png b/assets/textures/blue_directory.png deleted file mode 100644 index 5e871fedbcd8aa8891400c06f6f6bb662bd7611d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3981 zcmV;84|4E{P)q5gB-jcz76A*< z##iA#&{nWj5ClaKv9tHpNLcSALPU~TX79(DIhVU84c>mT8#ZD42?OgnRUK zEFpX(JYva!!q-ZV*Z4(os>UCRtw?AVT&ky*`or-*tf#H4@UXBynL)(&8NvwJ2SaQVr3Q@?i??#{_8RI zTjKw8+jjdV1q%-i0TJ>G;`e`-L7D3W2kZ_IAsPx1MUT(9kaiwddWIFkYldJ47#}6k zHdC!!VXKuN_<~oP82~P&TzTb;JuozyA6n%JJ8ui$7gnKE5U%4|xnd4!3%*zP?9y=A zvh#W2d7jAS^S)E5`cAdxoIf>HpE@<|IkR=V|FrMS9q&T@mKDi%!TbZb@~!T2#`4i% zD!%6&K*RVI@_Lf_MZ|bir1M$TL5cSUF~6L|cspYDx7`PlnE00O)&>FOt$1MLY32wX z%S})5P0>xydxo{!K)c&EdqABGNOIqh2`pP&cI#bY=H-5Q2 z{#o%nb}Lh&GWN2lUziZ}^W$Rb^}jH;5%?YO&%_jtJ&&FQJtOnjo|#m+eu__O#cNU7 zQ><`#{U^kSfAU&a>;A!WkBE~`-V@|uS+Aj&-r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z${b}nDQ67ICNjk9Qj9YDznUUCEv+^31)ee!^KMmQ?E{E3)Q`8 zRVLqymv5vd+SI^IQqQF3B!9?h93Ir0S}oIDHQz1UTX*|!UTkIlA_+{M%rB>pLW3!p z*`Y;lRLW2dED=tY)@=>8vNv%_VDdF{p*qQ`-y&DF|FcsI(spr}LlS)=MO@9>05e#q zrWr&xJM?K$TMzlI%um8fAx9S4hDlsOlC1Rcd#jHhnZW|-iY>R1j?$=_H3sv*diG`( zf~|^bnG)5(S=x;sbn`vZ<|)T4Bd>gBdi9PO$2?Sccn-Ks&pgd=^}f2YF3htCPs3@6 z#?uxPP4Zhgt5D|jYRh9s+W=GOEq$k+`ms3s!eb6p8JqpzXpRTp`s!7XIW zQ~F?4wmw&Z<<|?oTdVT;a}HXu@6#2YOIj`s($e57j@*Qe3fGYq&+I~;mSWK&hf$F- z@+(N|v#vA8lg#a0alk5;hiDa6TB-GLDj?77Br#Z%McML5TM5ExdjhAO!@4ak%)-}X zSpt(3EK6XQf|V(h20^KX^kW6wMp5x+cOE|PWb1f2!)5(lfnR33!)Bl@{oegtmoGq42I3*z#_tGSC%=2;kB56cf%S_5luw6Jtk$GoQgX2Jxp9nN#AdaLhivn%tul(<&( nFP7#P@dAy15zx#n7Y_Un8cD56sG16U00000NkvXXu0mjfs7tyJ 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