Create a haunted maze, retro-themed arcade game in Python. The game design looks like it…
- User
Create a haunted maze, retro-themed 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 external file uploads and instead create your own assets and designs.
- Assistant
Below is an example of a full Python script that uses Pygame to create a retro 80’s–style haunted maze arcade game. In this game you control a “hero” moving through a maze while avoiding wandering ghosts. The maze, characters, and assets are all created procedurally (with simple shapes and colors) so you don’t need any external files. You can run this code (assuming Pygame is installed) to experience a retro arcade feel!
Installation Note:
To install Pygame, run:
pip install pygameBelow is the complete code:
import pygame import random import sys # -------- Constants and Globals -------- # Dimensions for the maze grid TILE_SIZE = 40 # Each cell is 40x40 pixels. MAZE_WIDTH = 15 # Number of columns. MAZE_HEIGHT = 13 # Number of rows. SCREEN_WIDTH = TILE_SIZE * MAZE_WIDTH SCREEN_HEIGHT = TILE_SIZE * MAZE_HEIGHT # Colors (R,G,B) BLACK = ( 0, 0, 0) WHITE = (255, 255, 255) WALL_COLOR = ( 50, 50, 50) PATH_COLOR = ( 10, 10, 10) PLAYER_COLOR= ( 50, 255, 50) GHOST_COLOR = (255, 50, 50) HAUNTED_FLICKER = (80, 0, 80) # Update ghost movement every this many milliseconds GHOST_MOVE_INTERVAL = 500 # ghost moves every 500ms # -------- Maze Design -------- # 0 = free path, 1 = wall MAZE = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,0,0,0,1,0,0,0,0,0,1,0,0,0,1], [1,0,1,0,1,0,1,1,1,0,1,0,1,0,1], [1,0,1,0,0,0,0,0,1,0,0,0,1,0,1], [1,0,1,1,1,1,1,0,1,1,1,0,1,0,1], [1,0,0,0,0,0,1,0,0,0,1,0,1,0,1], [1,1,1,1,1,0,1,1,1,0,1,0,1,0,1], [1,0,0,0,1,0,0,0,1,0,0,0,0,0,1], [1,0,1,0,1,1,1,0,1,1,1,1,1,0,1], [1,0,1,0,0,0,0,0,0,0,0,0,1,0,1], [1,0,1,1,1,1,1,1,1,1,1,0,1,0,1], [1,0,0,0,0,0,0,0,0,0,1,0,0,0,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], ] # -------- Classes for the Game Entities -------- class Player: def __init__(self, row, col): self.row = row self.col = col def move(self, drow, dcol): new_row = self.row + drow new_col = self.col + dcol if 0 <= new_row < MAZE_HEIGHT and 0 <= new_col < MAZE_WIDTH: if MAZE[new_row][new_col] == 0: self.row = new_row self.col = new_col def draw(self, surface): # Draw the player as a block with a retro “pixel art” look. x = self.col * TILE_SIZE y = self.row * TILE_SIZE pygame.draw.rect(surface, PLAYER_COLOR, (x+5, y+5, TILE_SIZE-10, TILE_SIZE-10)) # Adding a retro outline pygame.draw.rect(surface, WHITE, (x+5, y+5, TILE_SIZE-10, TILE_SIZE-10), 2) class Ghost: def __init__(self, row, col): self.row = row self.col = col # Keep track of time for movement self.last_move = pygame.time.get_ticks() def update(self): now = pygame.time.get_ticks() if now - self.last_move > GHOST_MOVE_INTERVAL: # List possible moves (up/down/left/right not blocked by a wall) moves = [] directions = [(-1,0), (1,0), (0,-1), (0,1)] for drow, dcol in directions: new_r = self.row + drow new_c = self.col + dcol if (0 <= new_r < MAZE_HEIGHT and 0 <= new_c < MAZE_WIDTH and MAZE[new_r][new_c] == 0): moves.append((drow, dcol)) if moves: drow, dcol = random.choice(moves) self.row += drow self.col += dcol self.last_move = now def draw(self, surface): # Draw ghost as a circle with a retro “arcade” look. x = self.col * TILE_SIZE + TILE_SIZE // 2 y = self.row * TILE_SIZE + TILE_SIZE // 2 pygame.draw.circle(surface, GHOST_COLOR, (x, y), TILE_SIZE//2 - 4) # Add eyes for the ghost pygame.draw.circle(surface, WHITE, (x - 5, y - 5), 3) pygame.draw.circle(surface, WHITE, (x + 5, y - 5), 3) # -------- Functions for drawing the maze -------- def draw_maze(surface, flicker=False): for row in range(MAZE_HEIGHT): for col in range(MAZE_WIDTH): x = col * TILE_SIZE y = row * TILE_SIZE if MAZE[row][col] == 1: # Optionally use a flickering color for haunted walls. color = HAUNTED_FLICKER if flicker and (row+col) % 2 == 0 else WALL_COLOR pygame.draw.rect(surface, color, (x, y, TILE_SIZE, TILE_SIZE)) else: pygame.draw.rect(surface, PATH_COLOR, (x, y, TILE_SIZE, TILE_SIZE)) # -------- Main Game Function -------- def main(): pygame.init() screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) pygame.display.set_caption("Haunted Maze Arcade") clock = pygame.time.Clock() # Create a player starting at (1,1) player = Player(1, 1) # Create a few ghosts at some free locations in the maze: ghosts = [ Ghost(11, 1), Ghost(1, 13), Ghost(10, 7) ] # Variables for a "haunted flicker" effect flicker = False flicker_timer = 0 FLICKER_INTERVAL = 300 # milliseconds # Game state game_over = False font = pygame.font.SysFont("monospace", 36) while True: dt = clock.tick(30) # 30 FPS game loop flicker_timer += dt if flicker_timer > FLICKER_INTERVAL: flicker = not flicker flicker_timer = 0 # -------- Event Handling -------- for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN and not game_over: if event.key == pygame.K_LEFT: player.move(0, -1) elif event.key == pygame.K_RIGHT: player.move(0, 1) elif event.key == pygame.K_UP: player.move(-1, 0) elif event.key == pygame.K_DOWN: player.move(1, 0) # -------- Update Game Entities -------- if not game_over: for ghost in ghosts: ghost.update() # Check collision: if any ghost reaches the player, game over. for ghost in ghosts: if ghost.row == player.row and ghost.col == player.col: game_over = True # -------- Rendering -------- # Draw the maze with a haunted flicker effect. draw_maze(screen, flicker=flicker) # Draw the player and ghosts. player.draw(screen) for ghost in ghosts: ghost.draw(screen) # If game over, display "GAME OVER" if game_over: overlay = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT)) overlay.set_alpha(200) overlay.fill(BLACK) screen.blit(overlay, (0,0)) text = font.render("GAME OVER", True, WHITE) text_rect = text.get_rect(center=(SCREEN_WIDTH//2, SCREEN_HEIGHT//2)) screen.blit(text, text_rect) pygame.display.flip() if __name__ == '__main__': main()
How the Code Works
-
Maze and Assets:
The maze is defined as a two dimensional list where1represents a wall and0represents a path. All graphics (walls, paths, player, ghosts) are drawn using Pygame’s basic drawing functions. -
Player and Ghost Entities:
- The
Playerclass controls movement (only into open tiles) and drawing. - The
Ghostclass randomly picks a valid neighboring tile every half-second, giving the game a “haunted” unpredictable feel.
- The
-
Retro/Haunted Effects:
- Flickering walls (using alternating colors) add to the spooky, retro arcade vibe.
- Simple blocky shapes and pixel outlines evoke the look of 80’s arcade machines.
-
Game Loop & Collision:
- The game loop runs at 30 frames per second, handles user input (arrow keys), updates ghost positions, and checks for collisions (which trigger a “Game Over” overlay).
-
Self-Contained Assets:
All assets (colors, shapes, fonts) are created within the script so there is no need for external files.
To run the game, save the code to a file (e.g.,
haunted_maze.py), install Pygame if you haven’t already, and run:python haunted_maze.pyEnjoy exploring the haunted maze—just watch out for those ghosts!
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.