Mouvement pendant animations

This commit is contained in:
Tipragot 2023-10-29 23:40:17 +01:00
parent 793697ad50
commit 60787effa2
2 changed files with 32 additions and 20 deletions

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 LINES = 3
COLUMNS = 5 COLUMNS = 5
WAITING_SPACING = 200 SPACING = 200
SEARCHING_SPACING = 200
class State(Enum): class State(Enum):
@ -37,7 +36,7 @@ class State(Enum):
MOVING = 0 MOVING = 0
SEARCHING = 1 SEARCHING = 1
WAITING = 2 GAME_OVER = 2
class SelectedDirectory: class SelectedDirectory:
@ -76,11 +75,11 @@ class DirectoryPosition:
return self.x == value.x and self.y == value.y return self.x == value.x and self.y == value.y
return False return False
def screen_position(self, state: State) -> Vec2: def screen_position(self) -> Vec2:
""" """
Calcule la position de l'entité sur l'ecran. 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) offset = -(size * Vec2(COLUMNS - 1, LINES - 1) / 2)
first_position = Vec2(Display.WIDTH / 2, Display.HEIGHT / 2) + offset first_position = Vec2(Display.WIDTH / 2, Display.HEIGHT / 2) + offset
return first_position + Vec2(self.x, self.y) * size return first_position + Vec2(self.x, self.y) * size
@ -133,12 +132,13 @@ def __initialize_world(world: World):
] ]
for y in range(LINES): for y in range(LINES):
for x in range(COLUMNS): for x in range(COLUMNS):
position = DirectoryPosition(x, y)
entity = world.create_entity( entity = world.create_entity(
Position(0, 0), Position(position.screen_position()),
Order(1), Order(1),
Centered(), Centered(),
Texture("directory.png"), Texture("directory.png"),
DirectoryPosition(x, y), position,
) )
if x == 2 and y == 1: if x == 2 and y == 1:
@ -162,15 +162,17 @@ def __attacks(world: World):
world[AttackTimer] = AttackTimer(world[AttackTimer] + world[Delta]) world[AttackTimer] = AttackTimer(world[AttackTimer] + world[Delta])
timer = world[AttackTimer] timer = world[AttackTimer]
if timer >= world[AttackSpeed] and world[State] == State.MOVING: if timer >= world[AttackSpeed] and world[State] == State.MOVING:
entities = world.query(AttackPoint)
if len(entities) > 0:
world[State] = State.SEARCHING world[State] = State.SEARCHING
else: for entity in world.query(AttackPoint):
world[State] = State.WAITING
for entity in entities:
position = entity[AttackPoint] position = entity[AttackPoint]
for directory_entity in world.query(DirectoryPosition): for directory_entity in world.query(DirectoryPosition):
if directory_entity[DirectoryPosition] == position: if directory_entity[DirectoryPosition] == position:
if UserDirectory in directory_entity:
directory_entity[Animation] = Animation(
"search_directory_failed"
)
world[State] = State.GAME_OVER
else:
directory_entity[Animation] = Animation("search_directory") directory_entity[Animation] = Animation("search_directory")
del entity[AttackPoint] del entity[AttackPoint]
del entity[Position] del entity[Position]
@ -178,8 +180,6 @@ def __attacks(world: World):
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.WAITING
elif timer >= world[AttackSpeed] + 7 and world[State] == State.WAITING:
world[State] = State.MOVING world[State] = State.MOVING
for _ in range(10): for _ in range(10):
position = AttackPoint( position = AttackPoint(
@ -188,7 +188,7 @@ def __attacks(world: World):
) )
world.create_entity( world.create_entity(
position, position,
Position(position.screen_position(State.MOVING)), Position(position.screen_position()),
Order(50), Order(50),
Centered(), Centered(),
Texture("attack_point.png"), Texture("attack_point.png"),
@ -202,7 +202,7 @@ def __move_directories(world: World):
Permet de déplacer les dossiers avec la souris. Permet de déplacer les dossiers avec la souris.
""" """
# Si on n'est pas dans le bon state on annule # Si on n'est pas dans le bon state on annule
if world[State] == State.SEARCHING: if world[State] == State.GAME_OVER:
return return
# On met à jour la séléction # On met à jour la séléction
@ -253,8 +253,12 @@ def __move_directories(world: World):
if movement not in movements: if movement not in movements:
return return
# Si l'entité est animé on annule
if Animation in selected_entity:
return
# On trouve l'autre dossier # 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[ if entity != selected_entity and entity[
DirectoryPosition DirectoryPosition
] == DirectoryPosition( ] == DirectoryPosition(
@ -284,7 +288,7 @@ def __update_positions(world: World):
""" """
for entity in world.query(DirectoryPosition): for entity in world.query(DirectoryPosition):
position = entity[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) entity[Order] = Order(position.y + 1)