Ответы
Объяснение:
import pygame
import sys
import random
# Инициализация Pygame
pygame.init()
# Цвета
WHITE = (255, 255, 255)
RED = (255, 0, 0)
# Размер окна
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Hi Hit")
# Позиция игрока
player_x = WIDTH // 2
player_y = HEIGHT - 50
# Размеры игрока
player_width = 50
player_height = 50
# Позиция цели
target_x = random.randint(0, WIDTH - 50)
target_y = random.randint(50, HEIGHT - 50)
# Размеры цели
target_width = 50
target_height = 50
# Скорость игрока
player_speed = 5
# Основной игровой цикл
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
player_x -= player_speed
if keys[pygame.K_RIGHT]:
player_x += player_speed
screen.fill(WHITE)
# Рисуем игрока
pygame.draw.rect(screen, RED, (player_x, player_y, player_width, player_height))
# Рисуем цель
pygame.draw.rect(screen, RED, (target_x, target_y, target_width, target_height))
# Обновляем экран
pygame.display.update()
# Проверяем, столкнулся ли игрок с целью
if player_x < target_x + target_width and player_x + player_width > target_x and player_y < target_y + target_height and player_y + player_height > target_y:
target_x = random.randint(0, WIDTH - 50)
target_y = random.randint(50, HEIGHT - 50)
# Завершение Pygame
pygame.quit()
sys.exit()