diff --git a/highway_vector.py b/highway_vector.py index ce2de08..4b7a36d 100644 --- a/highway_vector.py +++ b/highway_vector.py @@ -218,15 +218,32 @@ class Enemy(Entity): self.health = 1 def update(self, entities): - # Movimiento de patrulla horizontal + # Calcular la posición objetiva horizontal target_gx = self.gx + (self.speed * self.direction) - # Rebotar en los bordes de la carretera + # 1. Rebotar si llega a los límites físicos de la carretera if target_gx <= 0.5 or target_gx >= GRID_SIZE_X - 0.5: self.direction *= -1 - target_gx = self.gx + (self.speed * self.direction) + return - self.gx = target_gx + # 2. Comprobar colisión con bloques u otras entidades sólidas + blocked = False + for entity in entities: + if entity != self and entity.is_solid: + # Comprobar la distancia con el bloque en la rejilla + if ( + abs(entity.gx - target_gx) < 0.6 + and abs(entity.gy - self.gy) < 0.6 + ): + blocked = True + break + + if blocked: + # Si se topa con un bloque empujable u otro obstáculo, invierte su rumbo + self.direction *= -1 + else: + # Si el camino está despejado, avanza + self.gx = target_gx class Player(Entity): diff --git a/img-versiones/version_1.2.png b/img-versiones/version_1.2.png new file mode 100644 index 0000000..513e9ee Binary files /dev/null and b/img-versiones/version_1.2.png differ