Generation

generate functionSat, 18 Jan 2025

creame un juego que sea visualmente divertido y en el que sea en la naturaleza y una gallina este escapándo de los tiros en una escopeta

Aquí te presento un juego simple en Python utilizando la biblioteca Pygame. En este juego, una gallina está escapando de los tiros de una escopeta en un entorno natural. **Requisitos previos** * Python 3.x * Pygame 2.x **Instalación de Pygame** Puedes instalar Pygame utilizando pip: ```bash pip install pygame ``` **Código del juego** ```python import pygame import sys import random # Inicializar Pygame pygame.init() # Constantes ANCHO = 800 ALTO = 600 COLOR_FONDO = (135, 206, 235) # Azul claro COLOR_GALLINA = (255, 215, 0) # Amarillo COLOR_TIROS = (255, 0, 0) # Rojo VELOCIDAD_GALLINA = 5 VELOCIDAD_TIROS = 10 # Crear pantalla pantalla = pygame.display.set_mode((ANCHO, ALTO)) # Crear reloj reloj = pygame.time.Clock() # Clases class Gallina: def __init__(self): self.x = random.randint(0, ANCHO) self.y = random.randint(0, ALTO) self.velocidad_x = random.choice([-VELOCIDAD_GALLINA, VELOCIDAD_GALLINA]) self.velocidad_y = random.choice([-VELOCIDAD_GALLINA, VELOCIDAD_GALLINA]) def dibujar(self, pantalla): pygame.draw.ellipse(pantalla, COLOR_GALLINA, (self.x, self.y, 50, 50)) def actualizar(self): self.x += self.velocidad_x self.y += self.velocidad_y if self.x < 0 or self.x > ANCHO - 50: self.velocidad_x *= -1 if self.y < 0 or self.y > ALTO - 50: self.velocidad_y *= -1 class Tiro: def __init__(self, x, y): self.x = x self.y = y self.velocidad_x = VELOCIDAD_TIROS def dibujar(self, pantalla): pygame.draw.rect(pantalla, COLOR_TIROS, (self.x, self.y, 10, 10)) def actualizar(self): self.x += self.velocidad_x # Crear objetos gallina = Gallina() tiros = [Tiro(ANCHO, random.randint(0, ALTO)) for _ in range(10)] # Bucle principal while True: for evento in pygame.event.get(): if evento.type == pygame.QUIT: pygame.quit() sys.exit() elif evento.type == pygame.MOUSEBUTTONDOWN: tiros.append(Tiro(evento.pos[0], evento.pos[1])) # Dibujar fondo pantalla.fill(COLOR_FONDO) # Dibujar gallina gallina.dibujar(pantalla) # Dibujar tiros for tiro in tiros: tiro.dibujar(pantalla) tiro.actualizar() # Comprobar colisión con gallina if (tiro.x < gallina.x + 50 and tiro.x + 10 > gallina.x and tiro.y < gallina.y + 50 and tiro.y + 10 > gallina.y): print("¡La gallina ha sido alcanzada!") pygame.quit() sys.exit() # Eliminar tiro si sale de la pantalla if tiro.x < 0: tiros.remove(tiro) # Actualizar gallina gallina.actualizar() # Actualizar pantalla pygame.display.flip() # Limitar velocidad reloj.tick(60) ``` **Cómo jugar** 1. Corre el código utilizando `python juego.py`. 2. La gallina se mueve aleatoriamente por la pantalla. 3. Puedes disparar a la gallina haciendo clic en la pantalla con el mouse. 4. Si la gallina es alcanzada, el juego se cierra. **Nota** * Este es un juego muy simple y puede ser mejorado en muchos aspectos. * La física del juego no es realista y la gallina no se comporta de manera realista. * El juego no tiene una forma de ganar o perder, solo se cierra cuando la gallina es alcanzada.

Want to kickstart your project?Use the new AI Studio to create your code