Ajout du flipping de direction pour les entités
This commit is contained in:
parent
21b973e9d8
commit
630176600a
|
@ -10,7 +10,9 @@ class Entity:
|
||||||
self.x = 8
|
self.x = 8
|
||||||
self.y = 8
|
self.y = 8
|
||||||
|
|
||||||
# Variables utilisées pour detecter les mouvements
|
self.direction = 0 # 0 : tourné vers la droite (ou sens par défaut), 1 : tourné vers la gauche (ou retourné)
|
||||||
|
|
||||||
|
# Variables utilisées pour détecter les mouvements
|
||||||
self.last_x = 0
|
self.last_x = 0
|
||||||
self.last_y = 0
|
self.last_y = 0
|
||||||
|
|
||||||
|
@ -97,6 +99,13 @@ class Entity:
|
||||||
def move(self, x: float, y: float, map_manager: MapManager):
|
def move(self, x: float, y: float, map_manager: MapManager):
|
||||||
"""Fait bouger l'entité en tenant compte des collisions."""
|
"""Fait bouger l'entité en tenant compte des collisions."""
|
||||||
|
|
||||||
|
# On vérifie le sens du mouvement pour changer self.direction
|
||||||
|
if x > 0:
|
||||||
|
self.direction = 0
|
||||||
|
elif x < 0:
|
||||||
|
self.direction = 1
|
||||||
|
# On ne met pas de else car si x = 0, on ne change pas de direction
|
||||||
|
|
||||||
# On normalise la vitesse
|
# On normalise la vitesse
|
||||||
initial_speed = math.sqrt(x**2+y**2)
|
initial_speed = math.sqrt(x**2+y**2)
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,10 @@ class Renderer:
|
||||||
anim: Anim = self.animations[entity.animation_name]
|
anim: Anim = self.animations[entity.animation_name]
|
||||||
frame = anim.get_frame(delta)
|
frame = anim.get_frame(delta)
|
||||||
|
|
||||||
|
# On flip l'image horizontalement si l'entité est retournée
|
||||||
|
if entity.direction == 1:
|
||||||
|
frame = transform.flip(frame, True, False)
|
||||||
|
|
||||||
# Si l'entité n'apparait pas à l'écran, on passe son rendu
|
# Si l'entité n'apparait pas à l'écran, on passe son rendu
|
||||||
if (entity.x - self.engine.camera.x + x_middle_offset + frame.get_width() < 0 or
|
if (entity.x - self.engine.camera.x + x_middle_offset + frame.get_width() < 0 or
|
||||||
entity.x - self.engine.camera.x - x_middle_offset - frame.get_width() > 0 or
|
entity.x - self.engine.camera.x - x_middle_offset - frame.get_width() > 0 or
|
||||||
|
|
Loading…
Reference in a new issue