Gameplay de la recherche dans les dossiers #44

Merged
CoCo_Sol merged 32 commits from directory-search into main 2023-10-30 00:49:00 +00:00
2 changed files with 32 additions and 20 deletions
Showing only changes of commit 60787effa2 - Show all commits

View file

@ -0,0 +1,8 @@
{
"offset": {
"x": 8,
"y": -83
},
"frame_count": 268,
"fps": 60
}

View file

@ -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)