diff --git a/highway_vector.py b/highway_vector.py index cc4fb73..2fb09c4 100644 --- a/highway_vector.py +++ b/highway_vector.py @@ -68,7 +68,6 @@ def draw_isometric_prism(surface, color, width=40, height=35): (cx, cy + 2 * h2), ] - # Sombra/Sombreado para volumen c_top = color c_left = tuple(max(0, c - 40) 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_right, right_pts) - # Bordes para definición 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), right_pts, 1) @@ -94,20 +92,18 @@ def create_placeholder_sprites(): base_pts = [(32, 48), (52, 38), (32, 28), (12, 38)] apex = (32, 8) - # Caras de la pirámide pygame.draw.polygon( surf_player, (200, 160, 0), [base_pts[3], base_pts[0], apex] - ) # Izquierda + ) pygame.draw.polygon( 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) 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) - # Bola superior pygame.draw.circle(surf_vortex, (255, 255, 200), (32, 12), 8) pygame.draw.circle(surf_vortex, (0, 0, 0), (32, 12), 8, 1) sprites["vortex"] = surf_vortex @@ -120,7 +116,7 @@ def create_placeholder_sprites(): None, COLOR_WHITE, width=32, height=35 ) - # 5. Enemigos Destructibles (Prismas por estado de vida) + # 5. Enemigos Destructibles sprites["enemy_red"] = draw_isometric_prism( None, COLOR_RED, width=32, height=35 ) @@ -261,12 +257,10 @@ class Enemy(Entity): def update(self, entities): 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: self.direction *= -1 return - # Comprobar bloqueos con bloques u otras entidades sólidas for entity in entities: if entity != self and entity.is_solid: if ( @@ -369,7 +363,7 @@ class Game: def __init__(self): 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.font = pygame.font.SysFont("monospace", 18, bold=True) self.sprite_mgr = SpriteManager() @@ -386,7 +380,6 @@ class Game: self.entities = [self.vortex, self.player] self.bullets = [] - # Escuadrón de reserva self.spares = [] for i in range(self.lives - 1): spare = Entity( @@ -398,41 +391,32 @@ class Game: ) 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): - # 1. Bloques de prueba blancos en diferentes carriles if y % 6 == 0: lane = (y * 3) % GRID_SIZE_X self.entities.append(PushBlock(lane, y)) - # 2. Enemigos destructibles (Prismas Rojos - 3 disparos) if y % 14 == 0: self.entities.append(Enemy(2.0, y, destructible=True)) - # 3. Enemigos indestructibles (Prismas Blancos - Solo bloqueables) if y % 20 == 0: self.entities.append(Enemy(5.0, y, destructible=False)) 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: if isinstance(entity, Enemy): - # Colisión con el Jugador - touch_player = ( - abs(entity.gx - self.player.gx) < 0.5 - and abs(entity.gy - self.player.gy) < 0.5 + player_hit = ( + abs(entity.gx - self.player.gx) < 0.6 + and abs(entity.gy - self.player.gy) < 0.6 ) - # Colisión con el VORTEX - touch_vortex = ( - abs(entity.gx - self.vortex.gx) < 0.6 - and abs(entity.gy - self.vortex.gy) < 0.6 + vortex_hit = ( + abs(entity.gx - self.vortex.gx) < 0.7 + and abs(entity.gy - self.vortex.gy) < 0.7 ) - if touch_player or touch_vortex: - self.lives -= 1 - if self.lives > 0: - self.reset_level() - return + if player_hit or vortex_hit: + return True # Devuelve True si hubo un impacto directo # Limpiar bloques destruidos y enemigos muertos for entity in self.entities[:]: @@ -440,6 +424,8 @@ class Game: self.entities.remove(entity) self.score += 200 + return False + def draw_hud(self): zone = int((GRID_SIZE_Y - self.vortex.gy) / 4) hud_text = f"ZONE: {zone:02d} | LIVES: {self.lives} | SCORE: {self.score:06d}" @@ -486,16 +472,19 @@ class Game: if not bullet.alive: 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) camera_offset_x = SCREEN_WIDTH // 2 - iso_x camera_offset_y = SCREEN_HEIGHT // 2 - iso_y + 100 self.screen.fill(COLOR_BG) - # Dibujar suelo for gy in range(0, GRID_SIZE_Y): for gx in range(0, GRID_SIZE_X): 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_GRID, pts, 1) - # Orden de renderizado por profundidad all_drawables = self.entities + self.bullets + self.spares sorted_entities = sorted( all_drawables, key=lambda e: e.gy, reverse=True diff --git a/img-versiones/version_3.0.png b/img-versiones/version_3.0.png new file mode 100644 index 0000000..6c1c711 Binary files /dev/null and b/img-versiones/version_3.0.png differ