Sure! How about a simple space shooter game with a graphical user interface using the pygame library? The player controls a spaceship and must shoot down enemies while avoiding obstacles. Here's a basic implementation:
First, make sure you have pygame installed:
bash
pip install pygame
Now, let's create the game:
python
import pygame
import random
# Initialize pygame
pygame.init()
# Set up display
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Space Shooter")
# Colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
# Ship and bullet properties
ship_img = pygame.image.load("your_ship_image_path.png") # Replace with actual image path
ship_rect = ship_img.get_rect()
ship_rect.centerx = WIDTH // 2
ship_rect.bottom = HEIGHT - 50
bullet_img = pygame.image.load("bullet.png")
bullets = []
# Enemies
enemy_img = pygame.image.load("enemy.png")
enemies = [
{"rect": pygame.Rect(100, random.randint(0, HEIGHT - 50), 50, 50), "color": RED}
for _ in range(5)
]
# Game Over
game_over = False
# Main Loop
clock = pygame.time.Clock()
while not game_over:
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
bullets.append(
pygame.Rect(ship_rect.centerx, ship_rect.top, 5, 10)
) # Create bullet
# Move ship
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
ship_rect.x -= 5
if keys[pygame.K_RIGHT]:
ship_rect.x += 5
# Move bullets
new_bullets = []
for bullet in bullets:
bullet.y -= 10
if bullet.y < 0:
new_bullets.append(bullet)
bullets = new_bullets
# Move enemies
new_enemies = []
for enemy in enemies:
enemy_rect = enemy["rect"]
enemy_rect.x += 5
if enemy_rect.right > WIDTH:
enemy_rect.x = -50
enemy_rect.y = random.randint(0, HEIGHT - 50)
new_enemies.append(enemy)
enemies = new_enemies
# Collision detection
for bullet in bullets:
for enemy in enemies:
if bullet.colliderect(enemy["rect"]):
enemies.remove(enemy)
bullets.remove(bullet)
break
# Draw
screen.fill(BLACK)
screen.blit(ship_img, ship_rect)
for enemy in enemies:
screen.blit(enemy_img, enemy["rect"])
for bullet in bullets:
screen.blit(bullet_img, bullet)
pygame.draw.rects(screen, WHITE, enemies, 1)
pygame.draw.rects(screen, RED, bullets, 1)
# Update display
pygame.display.update()
# Cap FPS
clock.tick(60)
# Quit pygame
pygame.quit()
Replace "your_ship_image_path.png" and "bullet.png" with the actual paths to your ship and bullet images. This is a very basic game with no sophisticated enemy AI or intricate graphics. You can enhance it further by adding features like multiple levels, power-ups, explosions, and more sophisticated enemy movement and firing mechanisms. Additionally, remember that game development often requires a lot more structure and organization than this simple example provides.
To run the game, copy the code into a Python file and execute it with pygame installed.
“code a game with a gui on python about whatever you want, be creative.” Conversation with command-r, from the LMArena Human Preference 100K dataset. The Chat Archive, 2026. https://thechatarchive.com/c/01m851epdf1699xy09ct3hf3sh