bloque empujando revision de sprites

This commit is contained in:
luisgulo 2026-10-04 15:17:20 +02:00
parent ac215e0e37
commit 11fdd51efb
2 changed files with 21 additions and 4 deletions

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB