Ajuste de colision y vidas
This commit is contained in:
parent
b25d67788e
commit
cd43dc8e3e
@ -68,7 +68,6 @@ def draw_isometric_prism(surface, color, width=40, height=35):
|
|||||||
(cx, cy + 2 * h2),
|
(cx, cy + 2 * h2),
|
||||||
]
|
]
|
||||||
|
|
||||||
# Sombra/Sombreado para volumen
|
|
||||||
c_top = color
|
c_top = color
|
||||||
c_left = tuple(max(0, c - 40) for c in color)
|
c_left = tuple(max(0, c - 40) for c in color)
|
||||||
c_right = tuple(max(0, c - 70) for c in color)
|
c_right = tuple(max(0, c - 70) for c in color)
|
||||||
@ -77,7 +76,6 @@ def draw_isometric_prism(surface, color, width=40, height=35):
|
|||||||
pygame.draw.polygon(surf, c_left, left_pts)
|
pygame.draw.polygon(surf, c_left, left_pts)
|
||||||
pygame.draw.polygon(surf, c_right, right_pts)
|
pygame.draw.polygon(surf, c_right, right_pts)
|
||||||
|
|
||||||
# Bordes para definición
|
|
||||||
pygame.draw.polygon(surf, (20, 20, 20), top_pts, 1)
|
pygame.draw.polygon(surf, (20, 20, 20), top_pts, 1)
|
||||||
pygame.draw.polygon(surf, (20, 20, 20), left_pts, 1)
|
pygame.draw.polygon(surf, (20, 20, 20), left_pts, 1)
|
||||||
pygame.draw.polygon(surf, (20, 20, 20), right_pts, 1)
|
pygame.draw.polygon(surf, (20, 20, 20), right_pts, 1)
|
||||||
@ -94,20 +92,18 @@ def create_placeholder_sprites():
|
|||||||
base_pts = [(32, 48), (52, 38), (32, 28), (12, 38)]
|
base_pts = [(32, 48), (52, 38), (32, 28), (12, 38)]
|
||||||
apex = (32, 8)
|
apex = (32, 8)
|
||||||
|
|
||||||
# Caras de la pirámide
|
|
||||||
pygame.draw.polygon(
|
pygame.draw.polygon(
|
||||||
surf_player, (200, 160, 0), [base_pts[3], base_pts[0], apex]
|
surf_player, (200, 160, 0), [base_pts[3], base_pts[0], apex]
|
||||||
) # Izquierda
|
)
|
||||||
pygame.draw.polygon(
|
pygame.draw.polygon(
|
||||||
surf_player, (255, 215, 0), [base_pts[0], base_pts[1], apex]
|
surf_player, (255, 215, 0), [base_pts[0], base_pts[1], apex]
|
||||||
) # Derecha
|
)
|
||||||
pygame.draw.polygon(surf_player, (255, 235, 100), base_pts) # Base
|
pygame.draw.polygon(surf_player, (255, 235, 100), base_pts)
|
||||||
pygame.draw.line(surf_player, (50, 50, 0), apex, base_pts[0], 2)
|
pygame.draw.line(surf_player, (50, 50, 0), apex, base_pts[0], 2)
|
||||||
sprites["player"] = surf_player
|
sprites["player"] = surf_player
|
||||||
|
|
||||||
# 2. VORTEX: Cubo amarillo con "bola" encima
|
# 2. VORTEX: Cubo amarillo con bola encima
|
||||||
surf_vortex = draw_isometric_prism(None, COLOR_YELLOW, width=38, height=25)
|
surf_vortex = draw_isometric_prism(None, COLOR_YELLOW, width=38, height=25)
|
||||||
# Bola superior
|
|
||||||
pygame.draw.circle(surf_vortex, (255, 255, 200), (32, 12), 8)
|
pygame.draw.circle(surf_vortex, (255, 255, 200), (32, 12), 8)
|
||||||
pygame.draw.circle(surf_vortex, (0, 0, 0), (32, 12), 8, 1)
|
pygame.draw.circle(surf_vortex, (0, 0, 0), (32, 12), 8, 1)
|
||||||
sprites["vortex"] = surf_vortex
|
sprites["vortex"] = surf_vortex
|
||||||
@ -120,7 +116,7 @@ def create_placeholder_sprites():
|
|||||||
None, COLOR_WHITE, width=32, height=35
|
None, COLOR_WHITE, width=32, height=35
|
||||||
)
|
)
|
||||||
|
|
||||||
# 5. Enemigos Destructibles (Prismas por estado de vida)
|
# 5. Enemigos Destructibles
|
||||||
sprites["enemy_red"] = draw_isometric_prism(
|
sprites["enemy_red"] = draw_isometric_prism(
|
||||||
None, COLOR_RED, width=32, height=35
|
None, COLOR_RED, width=32, height=35
|
||||||
)
|
)
|
||||||
@ -261,12 +257,10 @@ class Enemy(Entity):
|
|||||||
def update(self, entities):
|
def update(self, entities):
|
||||||
target_gx = self.gx + (self.speed * self.direction)
|
target_gx = self.gx + (self.speed * self.direction)
|
||||||
|
|
||||||
# Rebotar en los bordes 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
|
||||||
return
|
return
|
||||||
|
|
||||||
# Comprobar bloqueos con bloques u otras entidades sólidas
|
|
||||||
for entity in entities:
|
for entity in entities:
|
||||||
if entity != self and entity.is_solid:
|
if entity != self and entity.is_solid:
|
||||||
if (
|
if (
|
||||||
@ -369,7 +363,7 @@ class Game:
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||||
pygame.display.set_caption("Highway Encounter - Custom Enemies & Shapes")
|
pygame.display.set_caption("Highway Encounter - Fixed Collision & Life System")
|
||||||
self.clock = pygame.time.Clock()
|
self.clock = pygame.time.Clock()
|
||||||
self.font = pygame.font.SysFont("monospace", 18, bold=True)
|
self.font = pygame.font.SysFont("monospace", 18, bold=True)
|
||||||
self.sprite_mgr = SpriteManager()
|
self.sprite_mgr = SpriteManager()
|
||||||
@ -386,7 +380,6 @@ class Game:
|
|||||||
self.entities = [self.vortex, self.player]
|
self.entities = [self.vortex, self.player]
|
||||||
self.bullets = []
|
self.bullets = []
|
||||||
|
|
||||||
# Escuadrón de reserva
|
|
||||||
self.spares = []
|
self.spares = []
|
||||||
for i in range(self.lives - 1):
|
for i in range(self.lives - 1):
|
||||||
spare = Entity(
|
spare = Entity(
|
||||||
@ -398,41 +391,32 @@ class Game:
|
|||||||
)
|
)
|
||||||
self.spares.append(spare)
|
self.spares.append(spare)
|
||||||
|
|
||||||
# Generar bloques y enemigos a lo largo de toda la autopista (de y = 10 hasta la salida)
|
|
||||||
for y in range(10, GRID_SIZE_Y - 12):
|
for y in range(10, GRID_SIZE_Y - 12):
|
||||||
# 1. Bloques de prueba blancos en diferentes carriles
|
|
||||||
if y % 6 == 0:
|
if y % 6 == 0:
|
||||||
lane = (y * 3) % GRID_SIZE_X
|
lane = (y * 3) % GRID_SIZE_X
|
||||||
self.entities.append(PushBlock(lane, y))
|
self.entities.append(PushBlock(lane, y))
|
||||||
|
|
||||||
# 2. Enemigos destructibles (Prismas Rojos - 3 disparos)
|
|
||||||
if y % 14 == 0:
|
if y % 14 == 0:
|
||||||
self.entities.append(Enemy(2.0, y, destructible=True))
|
self.entities.append(Enemy(2.0, y, destructible=True))
|
||||||
|
|
||||||
# 3. Enemigos indestructibles (Prismas Blancos - Solo bloqueables)
|
|
||||||
if y % 20 == 0:
|
if y % 20 == 0:
|
||||||
self.entities.append(Enemy(5.0, y, destructible=False))
|
self.entities.append(Enemy(5.0, y, destructible=False))
|
||||||
|
|
||||||
def handle_collisions(self):
|
def handle_collisions(self):
|
||||||
# Muerte por contacto de un enemigo con el Jugador O con el VORTEX
|
# Detección precisa de colisión entre enemigos, jugador y VORTEX
|
||||||
for entity in self.entities:
|
for entity in self.entities:
|
||||||
if isinstance(entity, Enemy):
|
if isinstance(entity, Enemy):
|
||||||
# Colisión con el Jugador
|
player_hit = (
|
||||||
touch_player = (
|
abs(entity.gx - self.player.gx) < 0.6
|
||||||
abs(entity.gx - self.player.gx) < 0.5
|
and abs(entity.gy - self.player.gy) < 0.6
|
||||||
and abs(entity.gy - self.player.gy) < 0.5
|
|
||||||
)
|
)
|
||||||
# Colisión con el VORTEX
|
vortex_hit = (
|
||||||
touch_vortex = (
|
abs(entity.gx - self.vortex.gx) < 0.7
|
||||||
abs(entity.gx - self.vortex.gx) < 0.6
|
and abs(entity.gy - self.vortex.gy) < 0.7
|
||||||
and abs(entity.gy - self.vortex.gy) < 0.6
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if touch_player or touch_vortex:
|
if player_hit or vortex_hit:
|
||||||
self.lives -= 1
|
return True # Devuelve True si hubo un impacto directo
|
||||||
if self.lives > 0:
|
|
||||||
self.reset_level()
|
|
||||||
return
|
|
||||||
|
|
||||||
# Limpiar bloques destruidos y enemigos muertos
|
# Limpiar bloques destruidos y enemigos muertos
|
||||||
for entity in self.entities[:]:
|
for entity in self.entities[:]:
|
||||||
@ -440,6 +424,8 @@ class Game:
|
|||||||
self.entities.remove(entity)
|
self.entities.remove(entity)
|
||||||
self.score += 200
|
self.score += 200
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def draw_hud(self):
|
def draw_hud(self):
|
||||||
zone = int((GRID_SIZE_Y - self.vortex.gy) / 4)
|
zone = int((GRID_SIZE_Y - self.vortex.gy) / 4)
|
||||||
hud_text = f"ZONE: {zone:02d} | LIVES: {self.lives} | SCORE: {self.score:06d}"
|
hud_text = f"ZONE: {zone:02d} | LIVES: {self.lives} | SCORE: {self.score:06d}"
|
||||||
@ -486,16 +472,19 @@ class Game:
|
|||||||
if not bullet.alive:
|
if not bullet.alive:
|
||||||
self.bullets.remove(bullet)
|
self.bullets.remove(bullet)
|
||||||
|
|
||||||
self.handle_collisions()
|
# Verificar colisión y procesar pérdida de vida
|
||||||
|
if self.handle_collisions():
|
||||||
|
self.lives -= 1
|
||||||
|
if self.lives > 0:
|
||||||
|
self.reset_level()
|
||||||
|
continue # Reinicia el ciclo sin renderizar el estado fallido
|
||||||
|
|
||||||
# Desplazamiento de cámara centrado en el jugador
|
|
||||||
iso_x, iso_y = grid_to_iso(self.player.gx, self.player.gy)
|
iso_x, iso_y = grid_to_iso(self.player.gx, self.player.gy)
|
||||||
camera_offset_x = SCREEN_WIDTH // 2 - iso_x
|
camera_offset_x = SCREEN_WIDTH // 2 - iso_x
|
||||||
camera_offset_y = SCREEN_HEIGHT // 2 - iso_y + 100
|
camera_offset_y = SCREEN_HEIGHT // 2 - iso_y + 100
|
||||||
|
|
||||||
self.screen.fill(COLOR_BG)
|
self.screen.fill(COLOR_BG)
|
||||||
|
|
||||||
# Dibujar suelo
|
|
||||||
for gy in range(0, GRID_SIZE_Y):
|
for gy in range(0, GRID_SIZE_Y):
|
||||||
for gx in range(0, GRID_SIZE_X):
|
for gx in range(0, GRID_SIZE_X):
|
||||||
sx, sy = grid_to_iso(gx, gy)
|
sx, sy = grid_to_iso(gx, gy)
|
||||||
@ -521,7 +510,6 @@ class Game:
|
|||||||
pygame.draw.polygon(self.screen, COLOR_ROAD, pts)
|
pygame.draw.polygon(self.screen, COLOR_ROAD, pts)
|
||||||
pygame.draw.polygon(self.screen, COLOR_GRID, pts, 1)
|
pygame.draw.polygon(self.screen, COLOR_GRID, pts, 1)
|
||||||
|
|
||||||
# Orden de renderizado por profundidad
|
|
||||||
all_drawables = self.entities + self.bullets + self.spares
|
all_drawables = self.entities + self.bullets + self.spares
|
||||||
sorted_entities = sorted(
|
sorted_entities = sorted(
|
||||||
all_drawables, key=lambda e: e.gy, reverse=True
|
all_drawables, key=lambda e: e.gy, reverse=True
|
||||||
|
|||||||
BIN
img-versiones/version_3.0.png
Normal file
BIN
img-versiones/version_3.0.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
Loading…
x
Reference in New Issue
Block a user