bloque empujando revision de sprites
This commit is contained in:
parent
ac215e0e37
commit
11fdd51efb
@ -218,14 +218,31 @@ class Enemy(Entity):
|
|||||||
self.health = 1
|
self.health = 1
|
||||||
|
|
||||||
def update(self, entities):
|
def update(self, entities):
|
||||||
# Movimiento de patrulla horizontal
|
# Calcular la posición objetiva horizontal
|
||||||
target_gx = self.gx + (self.speed * self.direction)
|
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:
|
if target_gx <= 0.5 or target_gx >= GRID_SIZE_X - 0.5:
|
||||||
self.direction *= -1
|
self.direction *= -1
|
||||||
target_gx = self.gx + (self.speed * self.direction)
|
return
|
||||||
|
|
||||||
|
# 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
|
self.gx = target_gx
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
BIN
img-versiones/version_1.2.png
Normal file
BIN
img-versiones/version_1.2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
Loading…
x
Reference in New Issue
Block a user