Sure! Below is a complete Python script for a haunted maze, retro-themed arcade game inspired by 80's arcade aesthetics. It uses Pygame for graphics and input handling, and all assets (sprites, sounds, fonts) are generated programmatically or using simple shapes/colors to keep the retro vibe.
Features:
- Retro pixel art style maze
- Player moves with arrow keys
- Ghost enemies patrol the maze
- Collectibles (e.g., keys or orbs)
- Simple HUD with score and lives
- 80's arcade color palette and pixel fonts
- Sound effects generated with Pygame's tone generation (simple beeps)
- Maze walls, floor, and sprites all drawn with code (no external files)
How to run:
- Make sure you have Python 3 installed.
- Install Pygame if you don't have it:
pip install pygame
- Run the script below.
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH, SCREEN_HEIGHT = 640, 480
TILE_SIZE = 32
# Colors (retro 80's arcade palette)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
DARK_PURPLE = (48, 0, 48)
NEON_PINK = (255, 20, 147)
NEON_GREEN = (57, 255, 20)
NEON_BLUE = (20, 255, 255)
NEON_YELLOW = (255, 255, 0)
NEON_RED = (255, 0, 0)
GRAY = (100, 100, 100)
# Fonts
FONT_SIZE = 20
FONT = pygame.font.SysFont("Courier New", FONT_SIZE, bold=True)
# Create screen
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Haunted Maze - Retro Arcade")
# Clock for FPS
clock = pygame.time.Clock()
FPS = 60
# Maze layout (20x15 tiles)
# Legend:
# 0 = floor
# 1 = wall
# 2 = collectible (orb)
# 3 = exit door
maze_layout = [
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,2,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,2,0,1],
[1,0,1,1,0,1,0,1,1,1,0,1,0,1,1,1,0,1,0,1],
[1,0,1,0,0,0,0,1,2,1,0,0,0,1,2,1,0,1,0,1],
[1,0,1,0,1,1,0,1,0,1,1,1,0,1,0,1,0,1,0,1],
[1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1],
[1,1,1,1,0,1,1,1,1,1,0,1,1,1,0,1,1,1,0,1],
[1,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,1],
[1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,0,1,0,1],
[1,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1],
[1,1,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,1],
[1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,3,1],
[1,0,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1],
[1,2,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,2,0,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
]
MAZE_WIDTH = len(maze_layout[0])
MAZE_HEIGHT = len(maze_layout)
# Player class
class Player:
def __init__(self, x, y):
self.x = x
self.y = y
self.lives = 3
self.score = 0
self.color = NEON_GREEN
self.size = TILE_SIZE - 8
self.rect = pygame.Rect(self.x * TILE_SIZE + 4, self.y * TILE_SIZE + 4, self.size, self.size)
self.move_cooldown = 0
def draw(self, surface):
# Draw player as a neon green square with a pixel "eye"
pygame.draw.rect(surface, self.color, self.rect)
eye_rect = pygame.Rect(self.rect.x + self.size//3, self.rect.y + self.size//4, 4, 4)
pygame.draw.rect(surface, BLACK, eye_rect)
def move(self, dx, dy):
if self.move_cooldown > 0:
return
new_x = self.x + dx
new_y = self.y + dy
if 0 <= new_x < MAZE_WIDTH and 0 <= new_y < MAZE_HEIGHT:
if maze_layout[new_y][new_x] != 1:
self.x = new_x
self.y = new_y
self.rect.topleft = (self.x * TILE_SIZE + 4, self.y * TILE_SIZE + 4)
self.move_cooldown = 10 # frames cooldown to slow movement
def update(self):
if self.move_cooldown > 0:
self.move_cooldown -= 1
# Ghost enemy class
class Ghost:
def __init__(self, x, y):
self.x = x
self.y = y
self.color = NEON_PINK
self.size = TILE_SIZE - 10
self.rect = pygame.Rect(self.x * TILE_SIZE + 5, self.y * TILE_SIZE + 5, self.size, self.size)
self.direction = random.choice([(1,0), (-1,0), (0,1), (0,-1)])
self.move_timer = 0
def draw(self, surface):
# Draw ghost as a neon pink pixel-art ghost shape
px = self.rect.x
py = self.rect.y
s = self.size
# Body
pygame.draw.rect(surface, self.color, (px, py + s//4, s, s*3//4))
# Head (circle)
pygame.draw.circle(surface, self.color, (px + s//2, py + s//4), s//2)
# Eyes
eye_w, eye_h = 4, 6
pygame.draw.rect(surface, BLACK, (px + s//4, py + s//4, eye_w, eye_h))
pygame.draw.rect(surface, BLACK, (px + s//2 + 4, py + s//4, eye_w, eye_h))
def move(self):
if self.move_timer > 0:
self.move_timer -= 1
return
dx, dy = self.direction
new_x = self.x + dx
new_y = self.y + dy
if 0 <= new_x < MAZE_WIDTH and 0 <= new_y < MAZE_HEIGHT and maze_layout[new_y][new_x] != 1:
self.x = new_x
self.y = new_y
self.rect.topleft = (self.x * TILE_SIZE + 5, self.y * TILE_SIZE + 5)
else:
# Change direction randomly if blocked
self.direction = random.choice([(1,0), (-1,0), (0,1), (0,-1)])
self.move_timer = 20 # slower movement
# Collectible orb class
class Orb:
def __init__(self, x, y):
self.x = x
self.y = y
self.color = NEON_YELLOW
self.size = TILE_SIZE // 2
self.rect = pygame.Rect(self.x * TILE_SIZE + TILE_SIZE//4, self.y * TILE_SIZE + TILE_SIZE//4, self.size, self.size)
def draw(self, surface):
# Draw orb as a glowing yellow circle with pixel glow
pygame.draw.circle(surface, self.color, self.rect.center, self.size//2)
# Glow effect (simple)
glow_color = (255, 255, 150)
pygame.draw.circle(surface, glow_color, self.rect.center, self.size//2 + 2, 1)
# Draw maze function
def draw_maze(surface):
for y in range(MAZE_HEIGHT):
for x in range(MAZE_WIDTH):
tile = maze_layout[y][x]
px, py = x * TILE_SIZE, y * TILE_SIZE
if tile == 1:
# Wall - dark purple with neon blue outline
pygame.draw.rect(surface, DARK_PURPLE, (px, py, TILE_SIZE, TILE_SIZE))
pygame.draw.rect(surface, NEON_BLUE, (px, py, TILE_SIZE, TILE_SIZE), 2)
else:
# Floor - black with subtle grid lines
pygame.draw.rect(surface, BLACK, (px, py, TILE_SIZE, TILE_SIZE))
pygame.draw.rect(surface, GRAY, (px, py, TILE_SIZE, TILE_SIZE), 1)
if tile == 3:
# Exit door - neon red rectangle
pygame.draw.rect(surface, NEON_RED, (px + 8, py + 8, TILE_SIZE - 16, TILE_SIZE - 16))
# Generate orbs from maze layout
def get_orbs():
orbs = []
for y in range(MAZE_HEIGHT):
for x in range(MAZE_WIDTH):
if maze_layout[y][x] == 2:
orbs.append(Orb(x, y))
return orbs
# Sound effects (simple beep)
def play_beep(frequency=440, duration=100):
# Pygame doesn't have built-in tone generation, so we skip sound or use pygame.mixer.Sound with pre-made tones.
# For simplicity, no sound here.
pass
# Main game function
def main():
player = Player(1, 1)
orbs = get_orbs()
ghosts = [Ghost(10, 5), Ghost(15, 10), Ghost(5, 12)]
game_over = False
win = False
while True:
screen.fill(BLACK)
draw_maze(screen)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
keys = pygame.key.get_pressed()
if not game_over and not win:
if keys[pygame.K_LEFT]:
player.move(-1, 0)
elif keys[pygame.K_RIGHT]:
player.move(1, 0)
elif keys[pygame.K_UP]:
player.move(0, -1)
elif keys[pygame.K_DOWN]:
player.move(0, 1)
player.update()
# Draw orbs
for orb in orbs:
orb.draw(screen)
# Draw ghosts and move them
for ghost in ghosts:
ghost.move()
ghost.draw(screen)
# Draw player
player.draw(screen)
# Check collisions with orbs
for orb in orbs[:]:
if player.x == orb.x and player.y == orb.y:
orbs.remove(orb)
player.score += 10
play_beep(880, 100)
# Check collisions with ghosts
for ghost in ghosts:
if player.x == ghost.x and player.y == ghost.y:
player.lives -= 1
play_beep(220, 200)
# Reset player position
player.x, player.y = 1, 1
player.rect.topleft = (player.x * TILE_SIZE + 4, player.y * TILE_SIZE + 4)
if player.lives <= 0:
game_over = True
# Check if player reached exit door
if maze_layout[player.y][player.x] == 3 and len(orbs) == 0:
win = True
# HUD
score_text = FONT.render(f"SCORE: {player.score}", True, NEON_YELLOW)
lives_text = FONT.render(f"LIVES: {player.lives}", True, NEON_RED)
screen.blit(score_text, (10, SCREEN_HEIGHT - 30))
screen.blit(lives_text, (SCREEN_WIDTH - 120, SCREEN_HEIGHT - 30))
# Game over or win messages
if game_over:
msg = FONT.render("GAME OVER! PRESS R TO RESTART", True, NEON_RED)
screen.blit(msg, (SCREEN_WIDTH//2 - msg.get_width()//2, SCREEN_HEIGHT//2))
if keys[pygame.K_r]:
main()
return
elif win:
msg = FONT.render("YOU ESCAPED THE HAUNTED MAZE! PRESS R TO RESTART", True, NEON_GREEN)
screen.blit(msg, (SCREEN_WIDTH//2 - msg.get_width()//2, SCREEN_HEIGHT//2))
if keys[pygame.K_r]:
main()
return
pygame.display.flip()
clock.tick(FPS)
if __name__ == "__main__":
main()
Explanation:
- The maze is a 20x15 grid with walls, floor, collectibles (orbs), and an exit door.
- The player is a green square with a pixel eye, moving tile-by-tile.
- Ghosts are pink pixel-art ghosts that randomly patrol the maze.
- Collectibles are yellow glowing orbs.
- The player must collect all orbs before exiting through the red door.
- Colliding with ghosts costs a life and resets the player.
- The HUD shows score and lives in neon colors.
- The style uses neon colors and pixel fonts to evoke an 80's arcade feel.
- No external assets are used; everything is drawn with Pygame primitives.
- Sound effects are stubbed out (Pygame doesn't easily generate tones on the fly without external files).
If you want me to add sound effects or polish the visuals further, just ask!