import pygame import random import time pygame.init() # Pantalla ANCHO, ALTO = 800, 600 pantalla = pygame.display.set_mode((ANCHO, ALTO)) pygame.display.set_caption("Mini Mario Kart Rosa") # Colores VERDE = (0, 200, 0) GRIS = (100, 100, 100) ROSA = (255, 105, 180) BLANCO = (255, 255, 255) NEGRO = (0, 0, 0) AZUL = (0, 0, 255) # Reloj reloj = pygame.time.Clock() # Kart (jugadora) kart = pygame.Rect(375, 450, 50, 80) velocidad = 6 # Obstáculos (tipo caparazones) obstaculos = [] for i in range(6): obstaculos.append(pygame.Rect( random.randint(200, 550), random.randint(-600, -100), 40, 40 )) # Power-up power_up = pygame.Rect( random.randint(200, 550), random.randint(-800, -200), 30, 30 ) turbo = False turbo_inicio = 0 # Tiempo inicio = time.time() fuente = pygame.font.SysFont("Arial", 24) # Bucle principal jugando = True while jugando: reloj.tick(60) for evento in pygame.event.get(): if evento.type == pygame.QUIT: jugando = False # Fondo (pista) pantalla.fill(VERDE) pygame.draw.rect(pantalla, GRIS, (180, 0, 440, ALTO)) # Controles teclas = pygame.key.get_pressed() if teclas[pygame.K_LEFT] and kart.x > 180: kart.x -= velocidad if teclas[pygame.K_RIGHT] and kart.x < 550: kart.x += velocidad # Turbo if turbo and time.time() - turbo_inicio > 3: turbo = False velocidad = 6 # Dibujar kart pygame.draw.rect(pantalla, ROSA, kart) # Obstáculos for obs in obstaculos: obs.y += 7 if obs.y > ALTO: obs.y = random.randint(-400, -100) obs.x = random.randint(200, 550) pygame.draw.rect(pantalla, NEGRO, obs) if kart.colliderect(obs): jugando = False # Power-up power_up.y += 5 if power_up.y > ALTO: power_up.y = random.randint(-800, -200) power_up.x = random.randint(200, 550) pygame.draw.rect(pantalla, AZUL, power_up) if kart.colliderect(power_up): turbo = True velocidad = 10 turbo_inicio = time.time() power_up.y = random.randint(-800, -200) # Tiempo tiempo = int(time.time() - inicio) texto = fuente.render(f"Tiempo: {tiempo}s", True, BLANCO) pantalla.blit(texto, (10, 10)) pygame.display.update() pygame.quit()