Create a retro-themed, July 4th arcade game in Python. The game design looks like it…
- User
Create a retro-themed, July 4th arcade game in Python. The game design looks like it could have been played in an arcade back in the 80's. Do not rely on external file uploads and instead create your own assets and designs.
- Assistant
Below is an example of a complete, self-contained Python program that implements a retro, July 4th–themed arcade shooter. In this game you control a patriotic “cannon” at the bottom of the screen (decorated with red, white, and blue) that fires bullets upward to pop falling “firecracker” enemies. When you successfully hit an enemy, a burst of fireworks–complete with retro particle effects–explodes on the screen. The look and feel (and even the simple vector graphics) should remind you of classic ’80s arcade cabinets.
You can run the following code directly (provided you have Python 3 and Pygame installed). No external assets or files are needed because all images and particles are generated with Pygame’s drawing routines.
To run the code, simply copy it into a file (for example,
retro_july4th_arcade.py) and run it with Python.
import pygame import random import math # Pygame initialization pygame.init() WIDTH, HEIGHT = 800, 600 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Retro July 4th Arcade") clock = pygame.time.Clock() FPS = 60 # Colors (using patriotic red, white, blue and some neon accents) BLACK = (0, 0, 0) WHITE = (255, 255, 255) RED = (220, 20, 60) BLUE = (65, 105, 225) YELLOW = (255, 215, 0) ORANGE = (255, 140, 0) NEON_GREEN = (57, 255, 20) # Global Variables score = 0 # --- Helper functions --- def draw_star(surface, color, center, radius): """Draws a simple 5-point freehand star centered at 'center'.""" cx, cy = center points = [] for i in range(10): angle = math.radians(i * 36) r = radius if i % 2 == 0 else radius / 2 x = cx + r * math.cos(angle) y = cy + r * math.sin(angle) points.append((x, y)) pygame.draw.polygon(surface, color, points) # --- Sprite Classes --- class Player(pygame.sprite.Sprite): def __init__(self): super().__init__() # Create a retro-looking cannon shape with simple polygons. self.image = pygame.Surface((60, 40), pygame.SRCALPHA) # Draw a base (white rectangle with red and blue stripes to evoke the flag) pygame.draw.rect(self.image, WHITE, (0, 20, 60, 20)) pygame.draw.rect(self.image, RED, (0, 20, 20, 20)) pygame.draw.rect(self.image, BLUE, (40, 20, 20, 20)) # Draw the cannon barrel (a triangle shape) pygame.draw.polygon(self.image, NEON_GREEN, [(30, 0), (40, 20), (20, 20)]) self.rect = self.image.get_rect() self.rect.midbottom = (WIDTH // 2, HEIGHT - 10) self.speed = 7 def update(self): keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: self.rect.x -= self.speed if self.rect.left < 0: self.rect.left = 0 if keys[pygame.K_RIGHT]: self.rect.x += self.speed if self.rect.right > WIDTH: self.rect.right = WIDTH class Bullet(pygame.sprite.Sprite): def __init__(self, pos): super().__init__() self.image = pygame.Surface((6, 12), pygame.SRCALPHA) # Draw the bullet using a star shape (using patriotic colors) draw_star(self.image, YELLOW, (3, 6), 6) self.rect = self.image.get_rect(center=pos) self.speed = -10 def update(self): self.rect.y += self.speed if self.rect.bottom < 0: self.kill() class Enemy(pygame.sprite.Sprite): def __init__(self): super().__init__() # Create a simple circle “firecracker” with red-white-blue stripes. self.image = pygame.Surface((40, 40), pygame.SRCALPHA) pygame.draw.circle(self.image, RED, (20, 20), 20) pygame.draw.line(self.image, WHITE, (0, 20), (40, 20), 3) pygame.draw.line(self.image, BLUE, (20, 0), (20, 40), 3) self.rect = self.image.get_rect() self.rect.x = random.randrange(0, WIDTH - self.rect.width) self.rect.y = random.randrange(-100, -40) self.speedy = random.randrange(2, 5) def update(self): self.rect.y += self.speedy if self.rect.top > HEIGHT: self.kill() class Particle: """ A simple particle for explosion/firework effects. It doesn’t use the Sprite class to keep things light and retro. """ def __init__(self, pos, color): self.pos = list(pos) # Random velocity in every direction angle = random.uniform(0, 2 * math.pi) speed = random.uniform(2, 6) self.vel = [math.cos(angle) * speed, math.sin(angle) * speed] self.radius = random.randint(2, 4) self.color = color self.lifetime = random.randint(20, 40) def update(self): self.lifetime -= 1 self.pos[0] += self.vel[0] self.pos[1] += self.vel[1] # Gravity effect (optional) - gives a natural arc to particles. self.vel[1] += 0.1 def draw(self, surface): if self.lifetime > 0: # Fade the color over time. fade = max(0, self.lifetime / 40) faded_color = ( int(self.color[0] * fade), int(self.color[1] * fade), int(self.color[2] * fade) ) pygame.draw.circle(surface, faded_color, (int(self.pos[0]), int(self.pos[1])), self.radius) # --- Sprite Groups --- all_sprites = pygame.sprite.Group() bullets = pygame.sprite.Group() enemies = pygame.sprite.Group() player = Player() all_sprites.add(player) # Particle effects list (not using a Sprite group for simplicity) particles = [] # Enemy spawn event ENEMY_EVENT = pygame.USEREVENT + 1 pygame.time.set_timer(ENEMY_EVENT, 1000) # spawn an enemy every second # --- Game Loop --- running = True while running: clock.tick(FPS) # --- Process Input / Events --- for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Spawn enemy events if event.type == ENEMY_EVENT: enemy = Enemy() all_sprites.add(enemy) enemies.add(enemy) # Fire bullet with Space if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: bullet = Bullet(player.rect.midtop) all_sprites.add(bullet) bullets.add(bullet) # --- Update --- all_sprites.update() # Check collisions between bullets and enemies hits = pygame.sprite.groupcollide(enemies, bullets, True, True) for hit in hits: score += 10 # Create a burst of particles to simulate a retro firework explosion. for _ in range(30): color = random.choice([RED, BLUE, WHITE, ORANGE, YELLOW]) particles.append(Particle(hit.rect.center, color)) # Update particles for particle in particles[:]: particle.update() if particle.lifetime <= 0: particles.remove(particle) # --- Draw / Render --- screen.fill(BLACK) # Optionally, add some retro grid lines in the background for extra flavor. for x in range(0, WIDTH, 40): pygame.draw.line(screen, (40, 40, 40), (x, 0), (x, HEIGHT)) for y in range(0, HEIGHT, 40): pygame.draw.line(screen, (40, 40, 40), (0, y), (WIDTH, y)) all_sprites.draw(screen) # Draw particles on top. for particle in particles: particle.draw(screen) # Display score with a retro font font = pygame.font.SysFont("Courier", 24) score_text = font.render(f"Score: {score}", True, WHITE) screen.blit(score_text, (10, 10)) # --- Update Display --- pygame.display.flip() pygame.quit()
Explanation
-
Player Class:
The player is represented as a cannon with a white base accented with red and blue stripes and a neon‐green cannon barrel. Use the left/right arrow keys to move. -
Bullet Class:
When you press the space bar, you fire a bullet upward. The bullet is drawn using a star shape to evoke a retro “sparkle” effect. -
Enemy Class:
Enemies (depicted as simple firecracker–style circles with red, white, and blue details) fall from the top. If an enemy goes offscreen, it’s removed. -
Particle Effects:
When a bullet hits an enemy, a burst of particles (fireworks) is created. Each particle uses a random color from a patriotic palette and fades over time. -
Retro Background:
A grid overlays the black background to add extra retro arcade flavor. -
Game Loop:
The main loop handles input, spawns enemies every second, updates all sprites and particles, and draws everything. The score is updated each time you hit an enemy.
Enjoy this nostalgic blast of July 4th fun and feel free to expand or tweak it to your liking!
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.