Absolutely! Let’s create a simple, retro-style underwater arcade game in Python using Pygame . The game will feature:
python Copy code
import pygame
import random
import sys
# Initialize
pygame.init()
WIDTH, HEIGHT = 480, 640
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Aqua Diver - 80s Arcade")
clock = pygame.time.Clock()
FONT = pygame.font.SysFont("Courier", 24, bold=True)
# Colors
BG = (0, 40, 80)
WHITE = (255, 255, 255)
YELLOW = (255, 255, 0)
RED = (200, 40, 40)
GREEN = (0, 255, 120)
BLUE = (0, 180, 255)
ORANGE = (255, 140, 0)
# Game variables
player_speed = 5
enemy_speed = 3
treasure_speed = 2
score = 0
lives = 3
level = 1
# Player (diver) design
def draw_diver(x, y):
# Body
pygame.draw.rect(screen, BLUE, (x+8, y+8, 16, 24))
# Head
pygame.draw.circle(screen, WHITE, (x+16, y+8), 8)
# Mask
pygame.draw.rect(screen, (0, 200, 255), (x+10, y+4, 12, 8))
# Fins
pygame.draw.polygon(screen, ORANGE, [(x+8, y+32), (x+8, y+40), (x+12, y+32)])
pygame.draw.polygon(screen, ORANGE, [(x+24, y+32), (x+24, y+40), (x+20, y+32)])
# Enemy (jellyfish) design
def draw_jellyfish(x, y):
pygame.draw.ellipse(screen, RED, (x, y, 32, 24))
for i in range(4):
pygame.draw.line(screen, RED, (x+6+i*6, y+24), (x+6+i*6, y+32), 3)
# Treasure (chest) design
def draw_treasure(x, y):
pygame.draw.rect(screen, YELLOW, (x, y, 24, 16))
pygame.draw.rect(screen, ORANGE, (x, y+12, 24, 4))
pygame.draw.rect(screen, (120, 80, 0), (x+4, y+4, 16, 8))
# Bubble effect
def draw_bubble(x, y):
pygame.draw.circle(screen, WHITE, (x, y), 3, 1)
# Entities
player = pygame.Rect(WIDTH//2-16, HEIGHT-60, 32, 40)
enemies = []
treasures = []
bubbles = []
def spawn_enemy():
x = random.randint(0, WIDTH-32)
y = -40
enemies.append(pygame.Rect(x, y, 32, 40))
def spawn_treasure():
x = random.randint(0, WIDTH-24)
y = -20
treasures.append(pygame.Rect(x, y, 24, 16))
def spawn_bubble():
x = random.randint(0, WIDTH)
y = HEIGHT
bubbles.append([x, y])
# Main loop
SPAWNENEMY = pygame.USEREVENT+1
SPAWNTREASURE = pygame.USEREVENT+2
SPAWNBUBBLE = pygame.USEREVENT+3
pygame.time.set_timer(SPAWNENEMY, 1200)
pygame.time.set_timer(SPAWNTREASURE, 2500)
pygame.time.set_timer(SPAWNBUBBLE, 200)
running = True
while running:
screen.fill(BG)
# Draw bubbles
for b in bubbles:
draw_bubble(b[0], b[1])
b[1] -= 2
bubbles = [b for b in bubbles if b[1] > -5]
# Draw player
draw_diver(player.x, player.y)
# Draw enemies
for e in enemies:
draw_jellyfish(e.x, e.y)
e.y += enemy_speed
# Draw treasures
for t in treasures:
draw_treasure(t.x, t.y)
t.y += treasure_speed
# Move player
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.x > 0:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.x < WIDTH - player.width:
player.x += player_speed
if keys[pygame.K_UP] and player.y > 0:
player.y -= player_speed
if keys[pygame.K_DOWN] and player.y < HEIGHT - player.height:
player.y += player_speed
# Collisions
for e in enemies[:]:
if player.colliderect(e):
lives -= 1
enemies.remove(e)
if lives <= 0:
running = False
elif e.y > HEIGHT:
enemies.remove(e)
for t in treasures[:]:
if player.colliderect(t):
score += 10
treasures.remove(t)
elif t.y > HEIGHT:
treasures.remove(t)
# Level up
if score // 100 + 1 > level:
level += 1
enemy_speed += 1
treasure_speed += 0.5
# Draw HUD
score_text = FONT.render(f"Score: {score}", True, WHITE)
lives_text = FONT.render(f"Lives: {lives}", True, WHITE)
level_text = FONT.render(f"Level: {level}", True, WHITE)
screen.blit(score_text, (10, 10))
screen.blit(lives_text, (WIDTH-120, 10))
screen.blit(level_text, (WIDTH//2-50, 10))
# Events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == SPAWNENEMY:
spawn_enemy()
if event.type == SPAWNTREASURE:
spawn_treasure()
if event.type == SPAWNBUBBLE:
spawn_bubble()
pygame.display.flip()
clock.tick(60)
# Game Over screen
screen.fill(BG)
over_text = FONT.render("GAME OVER", True, YELLOW)
score_text = FONT.render(f"Final Score: {score}", True, WHITE)
screen.blit(over_text, (WIDTH//2-80, HEIGHT//2-40))
screen.blit(score_text, (WIDTH//2-100, HEIGHT//2))
pygame.display.flip()
pygame.time.wait(3000)
pygame.quit()
sys.exit()