Underwater Retro Arcade Game in Python
Here's a complete underwater-themed retro arcade game inspired by 1980s classics. The game features a submarine navigating through underwater obstacles while collecting treasure and avoiding enemies.
import pygame
import random
import math
import sys
from pygame import gfxdraw
# Initialize pygame
pygame.init()
# Screen dimensions
WIDTH, HEIGHT = 400, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Deep Sea Diver")
# Colors (using a limited 80s palette)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (0, 0, 128)
LIGHT_BLUE = (0, 191, 255)
GREEN = (0, 128, 0)
YELLOW = (255, 255, 0)
RED = (255, 0, 0)
PURPLE = (128, 0, 128)
ORANGE = (255, 165, 0)
# Game variables
clock = pygame.time.Clock()
FPS = 60
score = 0
lives = 3
game_over = False
level = 1
scroll_speed = 2
obstacle_timer = 0
enemy_timer = 0
treasure_timer = 0
# Player class
class Submarine:
def __init__(self):
self.x = WIDTH // 2
self.y = HEIGHT - 50
self.width = 30
self.height = 20
self.speed = 5
self.invincible = False
self.invincible_timer = 0
self.flash_timer = 0
def draw(self):
# Draw submarine body
if not self.invincible or (self.flash_timer // 5) % 2 == 0:
pygame.draw.rect(screen, YELLOW, (self.x - self.width // 2, self.y - self.height // 2, self.width, self.height))
# Draw periscope
pygame.draw.rect(screen, BLACK, (self.x - 2, self.y - self.height // 2 - 10, 4, 10))
# Draw propeller
pygame.draw.circle(screen, BLACK, (self.x - self.width // 2 - 5, self.y), 5)
# Draw windows
pygame.draw.rect(screen, LIGHT_BLUE, (self.x - 5, self.y - 5, 5, 5))
pygame.draw.rect(screen, LIGHT_BLUE, (self.x + 1, self.y - 5, 5, 5))
def move(self, keys):
if keys[pygame.K_LEFT] and self.x > self.width // 2:
self.x -= self.speed
if keys[pygame.K_RIGHT] and self.x < WIDTH - self.width // 2:
self.x += self.speed
if keys[pygame.K_UP] and self.y > self.height // 2:
self.y -= self.speed
if keys[pygame.K_DOWN] and self.y < HEIGHT - self.height // 2:
self.y += self.speed
def update(self):
if self.invincible:
self.invincible_timer += 1
self.flash_timer += 1
if self.invincible_timer > 120: # 2 seconds of invincibility
self.invincible = False
self.invincible_timer = 0
# Obstacle class
class Obstacle:
def __init__(self):
self.x = random.randint(20, WIDTH - 20)
self.y = -20
self.width = random.randint(30, 80)
self.height = random.randint(20, 50)
self.speed = scroll_speed + level * 0.5
self.type = random.choice(["rock", "coral", "shipwreck"])
def draw(self):
if self.type == "rock":
# Draw a jagged rock
points = [
(self.x - self.width // 2, self.y - self.height // 2),
(self.x - self.width // 4, self.y - self.height),
(self.x + self.width // 2, self.y - self.height // 2),
(self.x + self.width // 4, self.y),
(self.x - self.width // 4, self.y)
]
pygame.draw.polygon(screen, (100, 100, 100), points)
pygame.draw.polygon(screen, BLACK, points, 1)
elif self.type == "coral":
# Draw coral
for i in range(3):
pygame.draw.circle(screen, RED, (self.x - self.width // 2 + 10 + i * 15, self.y - self.height // 2 + 10), 8)
pygame.draw.circle(screen, PURPLE, (self.x - self.width // 2 + 5 + i * 15, self.y - self.height // 2), 10)
elif self.type == "shipwreck":
# Draw shipwreck
pygame.draw.rect(screen, (139, 69, 19), (self.x - self.width // 2, self.y - self.height // 2, self.width, self.height))
pygame.draw.line(screen, BLACK, (self.x - self.width // 2, self.y - self.height // 2),
(self.x + self.width // 2, self.y + self.height // 2), 2)
pygame.draw.line(screen, BLACK, (self.x - self.width // 2, self.y + self.height // 2),
(self.x + self.width // 2, self.y - self.height // 2), 2)
def update(self):
self.y += self.speed
return self.y > HEIGHT
# Enemy class
class Enemy:
def __init__(self):
self.x = random.randint(20, WIDTH - 20)
self.y = -30
self.width = 30
self.height = 20
self.speed = scroll_speed + level * 0.3
self.type = random.choice(["fish", "eel", "shark"])
def draw(self):
if self.type == "fish":
# Draw a simple fish
pygame.draw.ellipse(screen, ORANGE, (self.x - self.width // 2, self.y - self.height // 2, self.width, self.height))
pygame.draw.polygon(screen, ORANGE, [
(self.x + self.width // 2, self.y),
(self.x + self.width, self.y - 5),
(self.x + self.width, self.y + 5)
])
pygame.draw.circle(screen, BLACK, (self.x + self.width // 2 + 5, self.y), 2)
elif self.type == "eel":
# Draw an eel
pygame.draw.rect(screen, GREEN, (self.x - self.width // 2, self.y - self.height // 2, self.width, self.height))
pygame.draw.circle(screen, RED, (self.x + self.width // 2, self.y), 3)
elif self.type == "shark":
# Draw a shark
pygame.draw.polygon(screen, (128, 128, 128), [
(self.x, self.y - self.height // 2),
(self.x - self.width // 2, self.y),
(self.x, self.y + self.height // 2)
])
pygame.draw.circle(screen, BLACK, (self.x - self.width // 4, self.y - self.height // 4), 2)
pygame.draw.polygon(screen, WHITE, [
(self.x - self.width // 2, self.y - 2),
(self.x - self.width, self.y),
(self.x - self.width // 2, self.y + 2)
])
def update(self):
# Simple AI to follow player
if player.x < self.x:
self.x -= 0.5
elif player.x > self.x:
self.x += 0.5
self.y += self.speed
return self.y > HEIGHT
# Treasure class
class Treasure:
def __init__(self):
self.x = random.randint(20, WIDTH - 20)
self.y = -20
self.width = 15
self.height = 15
self.speed = scroll_speed + level * 0.2
self.type = random.choice(["gold", "gem", "chest"])
def draw(self):
if self.type == "gold":
pygame.draw.circle(screen, YELLOW, (self.x, self.y), self.width // 2)
pygame.draw.circle(screen, BLACK, (self.x, self.y), self.width // 2, 1)
elif self.type == "gem":
pygame.draw.polygon(screen, BLUE, [
(self.x, self.y - self.height // 2),
(self.x - self.width // 2, self.y),
(self.x, self.y + self.height // 2),
(self.x + self.width // 2, self.y)
])
elif self.type == "chest":
pygame.draw.rect(screen, (139, 69, 19), (self.x - self.width // 2, self.y - self.height // 2, self.width, self.height))
pygame.draw.rect(screen, BLACK, (self.x - self.width // 2, self.y - self.height // 2, self.width, self.height), 1)
pygame.draw.circle(screen, YELLOW, (self.x, self.y), 3)
def update(self):
self.y += self.speed
return self.y > HEIGHT
# Create player
player = Submarine()
# Game objects
obstacles = []
enemies = []
treasures = []
# Background stars
stars = []
for _ in range(50):
stars.append([
random.randint(0, WIDTH),
random.randint(0, HEIGHT),
random.randint(1, 3)
])
# Bubble particles
bubbles = []
for _ in range(20):
bubbles.append([
random.randint(0, WIDTH),
random.randint(HEIGHT // 2, HEIGHT),
random.randint(1, 3),
random.uniform(0.5, 2)
])
# Font (using a simple retro font)
def draw_text(text, size, x, y, color=WHITE):
font = pygame.font.SysFont('arial', size, bold=True)
text_surface = font.render(text, True, color)
text_rect = text_surface.get_rect(center=(x, y))
screen.blit(text_surface, text_rect)
# Game loop
running = True
while running:
# Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
if game_over and event.key == pygame.K_RETURN:
# Reset game
player = Submarine()
obstacles = []
enemies = []
treasures = []
score = 0
lives = 3
level = 1
scroll_speed = 2
game_over = False
if not game_over:
# Get keyboard input
keys = pygame.key.get_pressed()
player.move(keys)
player.update()
# Spawn obstacles
obstacle_timer += 1
if obstacle_timer > 60 - level * 5:
obstacles.append(Obstacle())
obstacle_timer = 0
# Spawn enemies
enemy_timer += 1
if enemy_timer > 120 - level * 10:
enemies.append(Enemy())
enemy_timer = 0
# Spawn treasures
treasure_timer += 1
if treasure_timer > 180 - level * 15:
treasures.append(Treasure())
treasure_timer = 0
# Update game objects
for obstacle in obstacles[:]:
if obstacle.update():
obstacles.remove(obstacle)
else:
# Check collision with player
if (player.x + player.width // 2 > obstacle.x - obstacle.width // 2 and
player.x - player.width // 2 < obstacle.x + obstacle.width // 2 and
player.y + player.height // 2 > obstacle.y - obstacle.height // 2 and
player.y - player.height // 2 < obstacle.y + obstacle.height // 2):
if not player.invincible:
lives -= 1
player.invincible = True
if lives <= 0:
game_over = True
for enemy in enemies[:]:
if enemy.update():
enemies.remove(enemy)
else:
# Check collision with player
if (player.x + player.width // 2 > enemy.x - enemy.width // 2 and
player.x - player.width // 2 < enemy.x + enemy.width // 2 and
player.y + player.height // 2 > enemy.y - enemy.height // 2 and
player.y - player.height // 2 < enemy.y + enemy.height // 2):
if not player.invincible:
lives -= 1
player.invincible = True
if lives <= 0:
game_over = True
for treasure in treasures[:]:
if treasure.update():
treasures.remove(treasure)
else:
# Check collision with player
if (player.x + player.width // 2 > treasure.x - treasure.width // 2 and
player.x - player.width // 2 < treasure.x + treasure.width // 2 and
player.y + player.height // 2 > treasure.y - treasure.height // 2 and
player.y - player.height // 2 < treasure.y + treasure.height // 2):
treasures.remove(treasure)
if treasure.type == "gold":
score += 100
elif treasure.type == "gem":
score += 200
elif treasure.type == "chest":
score += 500
# Level progression
if score > level * 2000:
level += 1
scroll_speed += 0.5
# Clear some obstacles when leveling up
obstacles = [o for o in obstacles if o.y < HEIGHT // 2]
enemies = [e for e in enemies if e.y < HEIGHT // 2]
# Update bubbles
for bubble in bubbles[:]:
bubble[1] -= bubble[3]
if bubble[1] < 0:
bubble[0] = random.randint(0, WIDTH)
bubble[1] = HEIGHT
bubble[2] = random.randint(1, 3)
bubble[3] = random.uniform(0.5, 2)
# Draw everything
screen.fill(BLACK)
# Draw background stars
for star in stars:
pygame.draw.circle(screen, WHITE, (star[0], star[1]), star[2])
# Draw bubbles
for bubble in bubbles:
pygame.draw.circle(screen, LIGHT_BLUE, (int(bubble[0]), int(bubble[1])), bubble[2])
# Draw game objects
for obstacle in obstacles:
obstacle.draw()
for enemy in enemies:
enemy.draw()
for treasure in treasures:
treasure.draw()
player.draw()
# Draw UI
pygame.draw.rect(screen, BLACK, (0, 0, WIDTH, 20))
draw_text(f"SCORE: {score}", 16, 70, 10)
draw_text(f"LEVEL: {level}", 16, WIDTH - 70, 10)
# Draw lives
for i in range(lives):
pygame.draw.rect(screen, YELLOW, (20 + i * 15, 5, 10, 10))
if game_over:
# Draw game over screen
overlay = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA)
overlay.fill((0, 0, 0, 180))
screen.blit(overlay, (0, 0))
draw_text("GAME OVER", 36, WIDTH // 2, HEIGHT // 2 - 40, RED)
draw_text(f"FINAL SCORE: {score}", 24, WIDTH // 2, HEIGHT // 2, WHITE)
draw_text("PRESS ENTER TO PLAY AGAIN", 18, WIDTH // 2, HEIGHT // 2 + 40, WHITE)
pygame.display.flip()
clock.tick(FPS)
pygame.quit()
sys.exit()
Game Features:
-
Retro Aesthetics:
- Limited color palette reminiscent of 80s arcade games
- Simple geometric shapes for all game elements
- Starfield background and bubble effects
-
Gameplay Mechanics:
- Control a submarine with arrow keys
- Avoid obstacles (rocks, coral, shipwrecks)
- Dodge enemies (fish, eels, sharks)
- Collect treasure (gold, gems, chests)
- Lives system with temporary invincibility after hits
-
Progression System:
- Increasing difficulty with each level
- Faster scrolling and more frequent obstacles/enemies
- Score-based level advancement
-
Game Elements:
- Player submarine with simple physics
- Multiple types of obstacles and enemies
- Different treasure types with varying point values
- Particle effects (bubbles) for atmosphere
To run this game, you'll need to have Pygame installed (pip install pygame). The game is completely self-contained with no external dependencies beyond Pygame itself.
The game captures the feel of classic arcade games with its simple but challenging gameplay, retro visuals, and progressive difficulty.