Make Pac-Man in python
# Pac-Man game in Python
# import the pygame library
import pygame
# initialize the pygame library
pygame.init()
# set the window size
window_width = 500
window_height = 500
# create the window
window = pygame.display.set_mode((window_width, window_height))
# set the window title
pygame.display.set_caption("Pac-Man")
# set the clock
clock = pygame.time.Clock()
# define colors
white = (255, 255, 255)
black = (0, 0, 0)
red = (255, 0, 0)
# define the Pac-Man character
pacman_width = 20
pacman_height = 20
pacman_x = window_width/2
pacman_y = window_height/2
pacman_speed = 5
# define the ghost character
ghost_width = 20
ghost_height = 20
ghost_x = window_width/2
ghost_y = window_height/2
ghost_speed = 5
# define the game loop
game_over = False
while not game_over:
# get all the events
for event in pygame.event.get():
# check if the event is the X button
if event.type == pygame.QUIT:
# if it is quit the game
game_over = True
# fill the window with black
window.fill(black)
# draw the Pac-Man character
pygame.draw.rect(window, white, (pacman_x, pacman_y, pacman_width, pacman_height))
# draw the ghost character
pygame.draw.rect(window, red, (ghost_x, ghost_y, ghost_width, ghost_height))
# update the window
pygame.display.update()
# tick the clock
clock.tick(60)
# quit the game
pygame.quit()