System de dossiers bloqué

This commit is contained in:
CoCo_Sol 2023-10-30 19:19:21 +01:00
parent 3c24188f97
commit 62eec44759

View file

@ -241,13 +241,47 @@ def __attacks(world: World):
del entity[Order] del entity[Order]
del entity[Centered] del entity[Centered]
del entity[Texture] del entity[Texture]
elif timer >= world[AttackSpeed] + 4.5 and world[State] == State.SEARCHING: elif timer >= world[AttackSpeed] + 4.5 and world[State] == State.SEARCHING:
world[State] = State.MOVING world[State] = State.MOVING
# 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):
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): for _ in range(10):
position = AttackPoint( x = random.randint(0, COLUMNS - 1)
random.randint(0, COLUMNS - 1), y = random.randint(0, LINES - 1)
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( world.create_entity(
position, position,
Position(position.screen_position()), Position(position.screen_position()),
@ -255,15 +289,6 @@ def __attacks(world: World):
Centered(), Centered(),
Texture("attack_point.png"), Texture("attack_point.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:
entity[BlockedDirectory] = BlockedDirectory()
world[AttackTimer] = AttackTimer(0.0) world[AttackTimer] = AttackTimer(0.0)
world[AttackSpeed] = AttackSpeed(world[AttackSpeed] * 0.9) world[AttackSpeed] = AttackSpeed(world[AttackSpeed] * 0.9)
@ -297,6 +322,11 @@ def __move_directories(world: World):
del world[SelectedDirectory] del world[SelectedDirectory]
return 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 # On calcule le déplacement de la souris
mouse_delta = mouse.position - selected_directory.position mouse_delta = mouse.position - selected_directory.position
@ -333,11 +363,14 @@ def __move_directories(world: World):
# On trouve l'autre dossier # On trouve l'autre dossier
for entity in world.query(DirectoryPosition, without=(Animation,)): for entity in world.query(DirectoryPosition, without=(Animation,)):
if entity != selected_entity and entity[ if (
DirectoryPosition entity != selected_entity
] == DirectoryPosition( and entity[DirectoryPosition]
== DirectoryPosition(
directory_position.x + movement[0], directory_position.x + movement[0],
directory_position.y + movement[1], directory_position.y + movement[1],
)
and BlockedDirectory not in entity
): ):
other_directory = entity other_directory = entity
break break