Help writing code

Question:
Please help why the game won’t start?

import pygame
import random

# Инициализация Pygame
pygame.init()

# Установка размеров окна
WIDTH = 800
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))

# Установка заголовка окна
pygame.display.set_caption("Boss Fight Game")

# Цвета
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)

# Установка шрифта для отображения текста
font = pygame.font.Font(None, 36)

# Установка переменных для хп и мана
hero_hp = 100
hero_mana = 100
boss_hp = 200

# Установка переменных для отката умений
q_cooldown = 0
e_cooldown = 0

# Создание спрайта героя
class Hero(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.Surface((50, 50))
        self.image.fill(BLUE)
        self.rect = self.image.get_rect()
        self.rect.center = (WIDTH // 2, HEIGHT // 2)

    def update(self):
        # Обновление координат героя
        keys = pygame.key.get_pressed()
        if keys[pygame.K_w]:
            self.rect.y -= 5
        if keys[pygame.K_a]:
            self.rect.x -= 5
        if keys[pygame.K_s]:
            self.rect.y += 5
        if keys[pygame.K_d]:
            self.rect.x += 5

# Создание спрайта босса
class Boss(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.Surface((100, 100))
        self.image.fill(RED)
        self.rect = self.image.get_rect()
        self.rect.center = (random.randint(100, WIDTH-100), random.randint(100, HEIGHT-100))

    def update(self):
        # Обновление координат босса
        self.rect.x += random.randint(-5, 5)
        self.rect.y += random.randint(-5, 5)

        # Атака босса
        if random.randint(1, 100) == 1:
            global hero_hp
            hero_hp -= 10

# Создание спрайта автоатаки
class Attack(pygame.sprite.Sprite):
    def __init__(self, x, y):
        super().__init__()
        self.image = pygame.Surface((10, 10))
        self.image.fill(GREEN)
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y

    def update(self):
        # Обновление координат автоатаки
        self.rect.y -= 10
        for attack in attack_sprites:
            hits = pygame.sprite.spritecollide(attack, boss_sprites, True)
            if hits:
                boss_hp -= 10
                attack.kill()

all_sprites = pygame.sprite.Group()
boss_sprites = pygame.sprite.Group()
attack_sprites = pygame.sprite.Group()

# Создание спрайтов
hero = Hero()
boss = Boss()
all_sprites.add(hero, boss)
boss_sprites.add(boss)

# Основной цикл игры
running = True
while running:
    # Обработка событий
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

        # Обработка нажатия клавиш
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_q and hero_mana >= 20 and q_cooldown == 0:
                # Создание спрайта умения Q
                hero_mana -= 20
                q_cooldown = 15
            if event.key == pygame.K_e and hero_mana >= 50 and e_cooldown == 0:
                # Создание спрайта умения E
                hero_mana -= 50
                e_cooldown = 5

            # Создание спрайта автоатаки
            if event.key == pygame.K_SPACE:
                attack = Attack(hero.rect.centerx, hero.rect.centery)
                all_sprites.add(attack)
                attack_sprites.add(attack)

    # Обновление координат спрайтов
    all_sprites.update()
    boss_sprites.update()
    attack_sprites.update()

    # Проверка столкновения автоатаки с боссом
    for attack in attack_sprites:
        hits = pygame.sprite.spritecollide(attack, boss_sprites, True)
        if hits:
            boss_hp -= 10
            attack.kill()

    # Отображение элементов на экране
    screen.fill(WHITE)
    all_sprites.draw(screen)

    # Отображение хп, мана и отката умений
    hero_hp_text = font.render(f"Hero HP: {hero_hp}", True, BLACK)
    screen.blit(hero_hp_text, (10, 10))
    hero_mana_text = font.render(f"Hero Mana: {hero_mana}", True, BLACK)
    screen.blit(hero_mana_text, (10, 50))
    boss_hp_text = font.render(f"Boss HP: {boss_hp}", True, BLACK)
    screen.blit(boss_hp_text, (WIDTH - 150, 10))
    q_cooldown_text = font.render(f"Q Cooldown: {q_cooldown}", True, BLACK)
    screen.blit(q_cooldown_text, (10, HEIGHT - 50))
    e_cooldown_text = font.render(f"E Cooldown: {e_cooldown}", True, BLACK)
    screen.blit(e_cooldown_text, (10, HEIGHT - 10))

    # Обновление отката умений
    if q_cooldown > 0:
        q_cooldown -= 1
    if e_cooldown > 0:
        e_cooldown -= 1

    # Проверка победы или поражения
    if hero_hp <= 0:
        gameover_text = font.render("Game Over", True, BLACK)
        screen.blit(gameover_text, (WIDTH // 2 - 50, HEIGHT // 2))
        running = False
    elif boss_hp <= 0:
        win_text = font.render("You Win!", True, BLACK)
        screen.blit(win_text, (WIDTH // 2 - 50, HEIGHT // 2))
        running = False

PyGame does not work at the moment for server issue. You need to wait till they fixed it.

3 Likes