Untitled
unknown
plain_text
24 days ago
1.5 kB
2
Indexable
Never
import pygame import sys # Initialize Pygame pygame.init() # Screen dimensions width, height = 448, 496 screen = pygame.display.set_mode((width, height)) pygame.display.set_caption("Simple Pac-Man") # Colors black = (0, 0, 0) yellow = (255, 255, 0) white = (255, 255, 255) blue = (0, 0, 255) # Pac-Man setup pacman_size = 20 pacman_x = width // 2 pacman_y = height // 2 pacman_speed = 4 direction = "STOP" # Maze layout (1 for walls, 0 for dots) maze = [ "1111111111111111111111111", "1000000000110000000000001", "1011110110110111011111011", "1011110110110111011111011", "1000000000000000000000001", "1011110111111111110111111", "1011110111111111110111111", "1000000110000000110000001", "1111010110111111011010111", "1111010110111111011010111", "1000000000000000000000001", "1011110111110111110111111", "1011110111110111110111111", "1000000000110000000000001", "1111111111111111111111111", ] # Convert maze string to list maze = [list(row) for row in maze] # Function to draw the maze def draw_maze(): block_size = 16 for y, row in enumerate(maze): for x, block in enumerate(row): if block == "1": pygame.draw.rect(screen, blue, (x * block_size, y * block_size, block_size, block_size)) if block == "0": pygame.draw.circle(screen, white, (x * block_size + block_size // 2, y * block_size + block_size // 2), 3) # Main game loop clock
Leave a Comment