Tempest Clone in Pygame with Glow Effects
Here's a Python implementation of a Tempest-style game using Pygame with glow effects for a cool aesthetic. This version includes the key elements of the original arcade game: a tunnel-like playfield, enemies crawling up from the bottom, and the player's ship zipping around the rim.
import pygame
import math
import random
from pygame import gfxdraw
import numpy as np
# Initialize pygame
pygame.init()
pygame.mixer.init()
# Screen dimensions
WIDTH, HEIGHT = 1200, 800
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Glowing Tempest Clone")
# Colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (0, 100, 255)
PURPLE = (150, 50, 255)
RED = (255, 50, 50)
GREEN = (50, 255, 50)
# Game parameters
FPS = 60
PLAYER_SPEED = 8
SHOT_SPEED = 12
ENEMY_SPEED = 2
ENEMY_SPAWN_RATE = 60 # frames
TUNNEL_SEGMENTS = 16
TUNNEL_DEPTH = 20
# Player
class Player:
def __init__(self):
self.segment = 0
self.pos = 0 # 0-15 for 16 segments
self.radius = 30
self.color = BLUE
self.shots = []
self.shot_cooldown = 0
self.alive = True
self.invincible = 0
self.super_shot = 0
def move(self, direction):
self.pos = (self.pos + direction) % TUNNEL_SEGMENTS
def shoot(self):
if self.shot_cooldown <= 0:
self.shots.append(Shot(self.pos, self.super_shot > 0))
self.shot_cooldown = 10
if self.super_shot > 0:
self.shot_cooldown = 5
def update(self):
if self.shot_cooldown > 0:
self.shot_cooldown -= 1
if self.invincible > 0:
self.invincible -= 1
if self.super_shot > 0:
self.super_shot -= 1
def draw(self, surface, tunnel_radius):
if self.invincible > 0 and pygame.time.get_ticks() % 200 < 100:
return # Blink effect when invincible
angle = 2 * math.pi * self.pos / TUNNEL_SEGMENTS
x = WIDTH // 2 + math.cos(angle) * tunnel_radius[0]
y = HEIGHT // 2 + math.sin(angle) * tunnel_radius[0]
# Glowing effect
for i in range(3, 0, -1):
alpha = 100 - i * 30
radius = self.radius + i * 3
color = (self.color[0], self.color[1], self.color[2], alpha)
pygame.gfxdraw.filled_circle(surface, int(x), int(y), radius, (*self.color, alpha))
# Main player
pygame.draw.circle(surface, self.color, (int(x), int(y)), self.radius)
# Draw a triangle pointing outward
points = [
(x + math.cos(angle) * self.radius, y + math.sin(angle) * self.radius),
(x + math.cos(angle + 0.3) * self.radius * 0.7, y + math.sin(angle + 0.3) * self.radius * 0.7),
(x + math.cos(angle - 0.3) * self.radius * 0.7, y + math.sin(angle - 0.3) * self.radius * 0.7)
]
pygame.draw.polygon(surface, WHITE, points)
# Shot
class Shot:
def __init__(self, segment, is_super):
self.segment = segment
self.depth = 0
self.speed = SHOT_SPEED
self.is_super = is_super
self.radius = 8 if is_super else 5
self.color = GREEN if is_super else WHITE
def update(self):
self.depth += self.speed
return self.depth > TUNNEL_DEPTH * 50 # Remove if past tunnel depth
def draw(self, surface, tunnel_radius):
angle = 2 * math.pi * self.segment / TUNNEL_SEGMENTS
depth_pct = min(1.0, self.depth / (TUNNEL_DEPTH * 50))
radius = tunnel_radius[0] * (1 - depth_pct) + tunnel_radius[-1] * depth_pct
x = WIDTH // 2 + math.cos(angle) * radius
y = HEIGHT // 2 + math.sin(angle) * radius
# Glowing effect
for i in range(2, 0, -1):
alpha = 100 - i * 40
r = self.radius + i * 2
pygame.gfxdraw.filled_circle(surface, int(x), int(y), r, (*self.color, alpha))
pygame.draw.circle(surface, self.color, (int(x), int(y)), self.radius)
# Enemy
class Enemy:
def __init__(self, segment, depth):
self.segment = segment
self.depth = depth
self.speed = ENEMY_SPEED * (0.5 + random.random())
self.radius = 15
self.color = RED
self.health = 2 if random.random() < 0.3 else 1 # 30% chance for stronger enemy
def update(self):
self.depth -= self.speed
return self.depth <= 0 # Reached the player
def draw(self, surface, tunnel_radius):
angle = 2 * math.pi * self.segment / TUNNEL_SEGMENTS
depth_pct = min(1.0, self.depth / (TUNNEL_DEPTH * 50))
radius = tunnel_radius[0] * (1 - depth_pct) + tunnel_radius[-1] * depth_pct
x = WIDTH // 2 + math.cos(angle) * radius
y = HEIGHT // 2 + math.sin(angle) * radius
# Glowing effect
glow_color = PURPLE if self.health > 1 else RED
for i in range(3, 0, -1):
alpha = 80 - i * 20
r = self.radius + i * 2
pygame.gfxdraw.filled_circle(surface, int(x), int(y), r, (*glow_color, alpha))
# Main enemy
color = PURPLE if self.health > 1 else RED
pygame.draw.circle(surface, color, (int(x), int(y)), self.radius)
# Spikes
for i in range(6):
spike_angle = angle + i * math.pi / 3
spike_x = x + math.cos(spike_angle) * self.radius * 1.3
spike_y = y + math.sin(spike_angle) * self.radius * 1.3
pygame.draw.line(surface, color, (x, y), (spike_x, spike_y), 2)
# Power-up
class PowerUp:
def __init__(self, segment, depth):
self.segment = segment
self.depth = depth
self.speed = ENEMY_SPEED * 0.7
self.radius = 10
self.type = random.choice(["super_shot", "extra_life", "invincible"])
def update(self):
self.depth -= self.speed
return self.depth <= 0 # Reached the player or bottom
def draw(self, surface, tunnel_radius):
angle = 2 * math.pi * self.segment / TUNNEL_SEGMENTS
depth_pct = min(1.0, self.depth / (TUNNEL_DEPTH * 50))
radius = tunnel_radius[0] * (1 - depth_pct) + tunnel_radius[-1] * depth_pct
x = WIDTH // 2 + math.cos(angle) * radius
y = HEIGHT // 2 + math.sin(angle) * radius
# Glowing effect
color = GREEN if self.type == "super_shot" else BLUE if self.type == "extra_life" else WHITE
for i in range(3, 0, -1):
alpha = 100 - i * 30
r = self.radius +