# Начало работы с Pygame

**Начало работы:**

1. Скачайте python с официального сайта <https://www.python.org/>.
2. Установить на вашу систему; При установке поставьте галочку "Add to PATH".
3. Проверьте установился ли python в систему. Найдите в меню пуск python и попробуйте выполнить, например, арифметическую операцию.

Далее устанавливаем библиотеку **pygame:**

1. заходим в командную строчку от имени администратора через кнопку пуск в панели задач пуск - **cmd**;
2. пишем в строку - **pip install pygame**, для установки библиотеки.

**Попробуйте написать первый тестовый проект:**

{% embed url="<https://www.pygame.org/docs/tut/PygameIntro.html>" %}

* Откройте **Visual Studio Code** на компьютере.
* Создайте новый файл: **ФАЙЛ > НОВЫЙ ФАЙЛ**. Создаться новая пустая вкладка с именем **Untitled-1.**
* Вставляем туда код, который написан для примера на странице по ссылке выше:

```python
import sys, pygame
pygame.init()

size = width, height = 320, 240
speed = [2, 2]
black = 0, 0, 0

screen = pygame.display.set_mode(size)

ball = pygame.image.load("intro_ball.gif")
ballrect = ball.get_rect()

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()

    ballrect = ballrect.move(speed)
    if ballrect.left < 0 or ballrect.right > width:
        speed[0] = -speed[0]
    if ballrect.top < 0 or ballrect.bottom > height:
        speed[1] = -speed[1]

    screen.fill(black)
    screen.blit(ball, ballrect)
    pygame.display.flip()
```

* Сохраняем файл проекта с кодом: **ФАЙЛ > СОХРАНИТЬ КАК...** В открывшемся окне выбираем куда сохранить (*ДОКУМЕНТЫ или ЗАГРУЗКИ*), в имя файла пишем, например, **test**, а тип файла выбираем: **Python.** Нажимаем на кнопку **СОХРАНИТЬ.**

![Окно сохранения файла проекта](/files/-M-PPyNQPkBA-kECGlLB)

* По ссылке выше сохраняем картинку мячика в папку с файлом проекта.
* Запускаем файл с расширением **py**.

И напоследок: для создания игры нам понадобиться **документация по библиотеке:**

{% embed url="<https://www.pygame.org/docs/>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://itdocs.kvantorium21.ru/introductory-module-in-it/arkhiv/keis-1b-igra-na-pygame/1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
