Код для игры пакмен.
- 2
- 0
- Опубликовано: 2024-02-12
import pygame
import sys
# Инициализация Pygame
pygame.init()
# Настройки игры
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
FPS = 60
# Цвета
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
# Создание игрового окна
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Pac-Man")
# Создание спрайта Пак-Мэна
pac_man = pygame.sprite.Sprite()
pac_man.image = pygame.Surface((20, 20))
pac_man.image.fill(YELLOW)
pac_man.rect = pac_man.image.get_rect()
pac_man.rect.center = (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)
# Создание спрайтов призраков
ghosts = pygame.sprite.Group()
for i in range(4):
ghost = pygame.sprite.Sprite()
ghost.image = pygame.Surface((20, 20))
ghost.image.fill(RED)
ghost.rect = ghost.image.get_rect()
ghost.rect.x = random.randint(0, SCREEN_WIDTH - ghost.rect.width)
ghost.rect.y = random.randint(0, SCREEN_HEIGHT - ghost.rect.height)
ghosts.add(ghost)
# Создание спрайтов точек
dots = pygame.sprite.Group()
for i in range(100):
dot = pygame.sprite.Sprite()
dot.image = pygame.Surface((5, 5))
dot.image.fill(WHITE)
dot.rect = dot.image.get_rect()
dot.rect.x = random.randint(0, SCREEN_WIDTH - dot.rect.width)