Amélioration de l'engine et ajout d'éléments de gameplay #20

Merged
yannis merged 29 commits from debut_jeu into main 2024-01-03 19:20:46 +00:00
Showing only changes of commit 350064792c - Show all commits

View file

@ -97,9 +97,15 @@ class Entity:
def move(self, x: float, y: float, map_manager: MapManager):
"""Fait bouger l'entité en tenant compte des collisions."""
# On normalise la vitesse
initial_speed = math.sqrt(x**2+y**2)
x = x/initial_speed*self.max_speed
y = y/initial_speed*self.max_speed
# On simule le mouvement. Si on ne rencontre pas de collision, on applique le mouvement
if not self.get_collisions(self.x + x, self.y, map_manager):
final_x = x
self.x += x
else:
# Si on a une collision, on avance pixel par pixel jusqu'à atteindre la collision
i = 0
@ -112,11 +118,11 @@ class Entity:
i -= 1
i += 1
final_x = i
self.x += i
# On répète le procédé avec l'ordonnée
if not self.get_collisions(self.x, self.y + y, map_manager):
final_y = y
self.y += y
else:
i = 0
if y > 0:
@ -128,16 +134,8 @@ class Entity:
i -= 1
i += 1
final_y = i
self.y += i
# On normalise le vecteur x, y pour ne pas dépacer la vitesse maximale de l'entité
total_len = math.sqrt(final_x**2+final_y**2)
if total_len == 0.:
return
self.x += final_x/total_len*self.max_speed
self.y += final_y/total_len*self.max_speed
def link_animation(self, name: str):
"""Met à jour l'animation en cours de l'entité."""