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
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here's a complete implementation of a retro-themed July 4th arcade game in Python using Pygame. The game features a player-controlled launcher at the bottom of the screen, shooting fireworks to hit star-shaped targets. The game includes scoring, lives, and a game over screen. The graphics are simple but evoke a retro feel with pixel art and a starry background.
python
import pygame
import sys
import random
# Initialize pygame
pygame.init()
pygame.mixer.init()
# Screen dimensions
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("July 4th Fireworks")
# Colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
YELLOW = (255, 255, 0)
# Load sounds (placeholder, in a real scenario, you'd load actual sound files)
try:
shoot_sound = pygame.mixer.Sound(buffer=pygame.sndarray.make_sound(buffer=pygame.sndarray.array([0] * 44100)))
explosion_sound = pygame.mixer.Sound(buffer=pygame.sndarray.make_sound(buffer=pygame.sndarray.array([0] * 44100)))
except:
# If sound loading fails, create dummy functions
def dummy_sound():
pass
shoot_sound = dummy_sound
explosion_sound = dummy_sound
# Player class
class Player(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image = pygame.Surface((50, 30))
self.image.fill(GREEN)
self.rect = self.image.get_rect()
self.rect.centerx = WIDTH // 2
self.rect.bottom = HEIGHT - 10
self.speed = 8
def update(self):
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and self.rect.left > 0:
self.rect.x -= self.speed
if keys[pygame.K_RIGHT] and self.rect.right < WIDTH:
self.rect.x += self.speed
def shoot(self):
firework = Firework(self.rect.centerx, self.rect.top)
all_sprites.add(firework)
fireworks.add(firework)
shoot_sound.play()
# Firework class
class Firework(pygame.sprite.Sprite):
def __init__(self, x, y):
super().__init__()
self.image = pygame.Surface((10, 20))
self.image.fill(RED)
self.rect = self.image.get_rect()
self.rect.centerx = x
self.rect.bottom = y
self.speed = 10
def update(self):
self.rect.y -= self.speed
if self.rect.bottom < 0:
self.kill()
# Target class
class Target(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image = self.create_star()
self.rect = self.image.get_rect()
self.rect.x = random.randrange(WIDTH - self.rect.width)
self.rect.y = random.randrange(-100, -40)
self.speedy = random.randrange(1, 5)
self.speedx = random.randrange(-2, 2)
def create_star(self):
star = pygame.Surface((30, 30), pygame.SRCALPHA)
pygame.draw.polygon(star, YELLOW, [(15, 0), (19, 10), (30, 10), (22, 17), (26, 30), (15, 23), (4, 30), (8, 17), (0, 10), (11, 10)])
return star
def update(self):
self.rect.y += self.speedy
self.rect.x += self.speedx
if self.rect.top > HEIGHT + 10 or self.rect.left < -25 or self.rect.right > WIDTH + 25:
self.kill()
# Background class
class Background(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image = pygame.Surface((WIDTH, HEIGHT))
self.image.fill(BLACK)
# Draw stars in the background
for _ in range(100):
x = random.randrange(WIDTH)
y = random.randrange(HEIGHT)
pygame.draw.circle(self.image, WHITE, (x, y), 1)
self.rect = self.image.get_rect()
# Game Over Screen
def game_over_screen(score):
screen.fill(BLACK)
font = pygame.font.SysFont('Arial', 50)
game_over_text = font.render("GAME OVER", True, RED)
score_text = font.render(f"Score: {score}", True, WHITE)
restart_text = font.render("Press R to Restart", True, WHITE)
screen.blit(game_over_text, (WIDTH // 2 - game_over_text.get_width() // 2, HEIGHT // 2 - 100))
screen.blit(score_text, (WIDTH // 2 - score_text.get_width() // 2, HEIGHT // 2))
screen.blit(restart_text, (WIDTH // 2 - restart_text.get_width() // 2, HEIGHT // 2 + 100))
pygame.display.flip()
waiting = True
while waiting:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_r:
waiting = False
if event.key == pygame.K_q:
pygame.quit()
sys.exit()
# Main game function
def main():
global all_sprites, fireworks, targets, player, score, lives
# Initialize sprites
all_sprites = pygame.sprite.Group()
fireworks = pygame.sprite.Group()
targets = pygame.sprite.Group()
# Create background
background = Background()
all_sprites.add(background)
# Create player
player = Player()
all_sprites.add(player)
# Spawn targets
for i in range(8):
target = Target()
all_sprites.add(target)
targets.add(target)
# Game loop
clock = pygame.time.Clock()
score = 0
lives = 3
font = pygame.font.SysFont('Arial', 30)
running = True
while running:
# Keep loop running at the right speed
clock.tick(60)
# Process input (events)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
player.shoot()
# Update
all_sprites.update()
# Check for firework-target collisions
hits = pygame.sprite.groupcollide(fireworks, targets, True, True)
for hit in hits:
score += 10
explosion_sound.play()
target = Target()
all_sprites.add(target)
targets.add(target)
# Check if targets reach the bottom
for target in targets:
if target.rect.top > HEIGHT:
target.kill()
lives -= 1
if lives <= 0:
running = False
# Spawn new targets if there are too few
if len(targets) < 5:
target = Target()
all_sprites.add(target)
targets.add(target)
# Draw / render
screen.fill(BLACK)
all_sprites.draw(screen)
# Draw score and lives
score_text = font.render(f"Score: {score}", True, WHITE)
lives_text = font.render(f"Lives: {lives}", True, WHITE)
screen.blit(score_text, (10, 10))
screen.blit(lives_text, (10, 50))
# Flip the display
pygame.display.flip()
# Game over
game_over_screen(score)
main() # Restart the game
# Start the game
if __name__ == "__main__":
main()
This code creates a simple but functional retro-themed July 4th arcade game. The player controls a launcher at the bottom of the screen, shooting fireworks to hit star-shaped targets. The game includes scoring, lives, and a game over screen. The graphics are simple but evoke a retro feel with pixel art and a starry background.