сделай так ,что музыка с названием "musice" проигрывался на 70% тише и звук выстрела не накладывался на musice:import pygame
import random
import sqlite3
from pygame.locals import QUIT, KEYDOWN, K_RETURN, K_r, K_ESCAPE

pygame.init()

Константы
WIDTH, HEIGHT = 800, 600
BULLET_RADIUS = 10
BULLET_SPEED = 8
TRIANGLE_SPEED = 5
SQUARE_SPEED = 2
EXPLOSION_DURATION = 50
SQUARES_PER_WAVE = 7
WAVE_INCREASE_INTERVAL = 6
EXTRA_SQUARES_PER_WAVE = 4
INITIAL_LIVES = 3
FULL_EXPLOSION_TIME = 3000
EXPLOSION_COLOR_CHANGE_INTERVAL = 500
BULLET_COUNT_THRESHOLD = 30
RESET_THRESHOLD = 180
MAX_BULLETS = 5
BULLET_SIZE_INCREASE_STEP = 0.1
BULLET_SIZE_INCREASE_LIMIT = 10
BULLET_SPACING = 10
SPEED_INCREASE_FACTOR = 0.05
WAVE_PAUSE_DURATION = 10000
SPAWN_MARGIN = 50

Цвета
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)

Путь к изображениям
BACKGROUND_IMAGE_PATH = r"./background.png"
SHIP_IMAGE_PATH = r"./ship.png"
ENEMY_IMAGE_PATH = r"./enemy.png"

Создание окна
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Triangle Shooter")

Загрузка изображений
background = pygame.image.load(BACKGROUND_IMAGE_PATH)
background = pygame.transform.scale(background, (WIDTH, HEIGHT))

ship_image = pygame.image.load(SHIP_IMAGE_PATH)
ship_image = pygame.transform.scale(ship_image, (60, 60))

enemy_image = pygame.image.load(ENEMY_IMAGE_PATH)
enemy_image = pygame.transform.scale(enemy_image, (60, 60))

Загрузка звука
shot_sound = pygame.mixer.Sound("shot.mp3")
musice = pygame.mixer.Sound("musice.mp3")

Работа с базой данных
conn = sqlite3.connect('leaderboard.db')
cursor = conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS leaderboard
(name TEXT, login TEXT, score INTEGER)''')
conn.commit()

Получение информации о пользователе
def get_user_info():
name = input("Введите ваше имя: ")
login = input("Введите ваш логин: ")
return name, login

Обновление таблицы лидеров
def update_leaderboard(name, login, score):
cursor.execute("INSERT INTO leaderboard (name, login, score) VALUES (?, ?, ?)", (name, login, score))
conn.commit()

Очистка таблицы лидеров
def clear_leaderboard():
cursor.execute("DELETE FROM leaderboard")
conn.commit()

Отображение таблицы лидеров в новом окне
def display_leaderboard():
leaderboard_window = pygame.display.set_mode((400, 500))
pygame.display.set_caption("Leaderboard")


font = pygame.font.SysFont(None, 36)
cursor.execute("SELECT * FROM leaderboard ORDER BY score DESC LIMIT 10")
results = cursor.fetchall()

while len(results) < 10:
    results.append(("-", "-", 0))

running = True
while running:
    for event in pygame.event.get():
        if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
            running = False
        elif event.type == KEYDOWN:
            if event.key == pygame.K_c:
                clear_leaderboard()
                results = []
                while len(results) < 10:
                    results.append(("-", "-", 0))
        
    leaderboard_window.fill(WHITE)

    y_offset = 50
    for idx, (name, login, score) in enumerate(results):
        text = f"{idx + 1}. {name} ({login}) - {score}"
        text_surf = font.render(text, True, BLACK)
        leaderboard_window.blit(text_surf, (20, y_offset))
        y_offset += 40

    pygame.display.flip()
    pygame.time.delay(100)
Пользователь
user_name, user_login = get_user_info()

Игровые объекты и состояние
triangle_pos = [WIDTH // 2, HEIGHT - 60]
squares = []
bullets = []
explosions = []
player_explosions = []
destroyed_squares = 0
current_wave = 1
squares_in_wave = SQUARES_PER_WAVE
lives = INITIAL_LIVES
game_over = False
full_screen_explosion_started = False
full_screen_explosion_start_time = 0
wave_pause_start_time = None
in_wave_pause = False
current_bullet_count = 1
current_bullet_size = BULLET_RADIUS
bullet_size_increase_count = 0

Основной игровой цикл
clock = pygame.time.Clock()
running = True

def draw_bullet(position):
pygame.draw.circle(screen, BLUE, position, int(current_bullet_size))

def draw_explosion(position, duration, player=False):
if player:
color = BLUE if duration % 2 == 0 else WHITE
else:
color = YELLOW if duration % 2 == 0 else BLUE
pygame.draw.rect(screen, color, (position[0] - 30, position[1] - 30, 90, 90))

def draw_text_with_outline(text, font, x, y):
outline_color = BLACK
text_color = WHITE
outline_width = 2


outline_surface = font.render(text, True, outline_color)
for dx in [-outline_width, 0, outline_width]:
    for dy in [-outline_width, 0, outline_width]:
        screen.blit(outline_surface, (x + dx, y + dy))

text_surface = font.render(text, True, text_color)
screen.blit(text_surface, (x, y))
def draw_score_and_lives():
font = pygame.font.SysFont(None, 36)
draw_text_with_outline(f"Destroyed Squares: {destroyed_squares}", font, 10, 10)
draw_text_with_outline(f"Lives: {lives}", font, 10, 50)

def draw_full_screen_explosion():
elapsed_time = pygame.time.get_ticks() - full_screen_explosion_start_time
color_phase = (elapsed_time // EXPLOSION_COLOR_CHANGE_INTERVAL) % 3
color = [YELLOW, WHITE, BLUE][color_phase]
screen.fill(color)

while running:
if not game_over:
musice.play()
screen.blit(background, (0, 0))


    keys = pygame.key.get_pressed()
    if keys[pygame.K_a] and triangle_pos[0] > 0:
        triangle_pos[0] -= TRIANGLE_SPEED
    if keys[pygame.K_d] and triangle_pos[0] < WIDTH - 60:
        triangle_pos[0] += TRIANGLE_SPEED
    if keys[pygame.K_w] and triangle_pos[1] > 0:
        triangle_pos[1] -= TRIANGLE_SPEED
    if keys[pygame.K_s] and triangle_pos[1] < HEIGHT - 60:
        triangle_pos[1] += TRIANGLE_SPEED

    for event in pygame.event.get():
        if event.type == QUIT:
            running = False
        elif event.type == KEYDOWN:
            if event.key == K_RETURN and not in_wave_pause:
                # Проигрываем звук при нажатии Enter
                shot_sound.play()
                for i in range(current_bullet_count):
                    offset = (i - (current_bullet_count - 1) / 2) * BULLET_SPACING
                    bullets.append([triangle_pos[0] + offset, triangle_pos[1]])

    if in_wave_pause:
        if pygame.time.get_ticks() - wave_pause_start_time > WAVE_PAUSE_DURATION:
            in_wave_pause = False
    else:
        if len(squares) == 0:
            for _ in range(squares_in_wave):
                x = random.randint(SPAWN_MARGIN, WIDTH - 60 - SPAWN_MARGIN)
                y = random.randint(-150, -60)
                squares.append([x, y])

        for square in squares[:]:
            square[1] += SQUARE_SPEED
            if square[1] > HEIGHT:
                squares.remove(square)
            if (square[0] < triangle_pos[0] < square[0] + 60 or square[0] < triangle_pos[0] + 60 < square[0] + 60) and (
                    square[1] < triangle_pos[1] < square[1] + 60 or square[1] < triangle_pos[1] + 60 < square[1] + 60):
                if not full_screen_explosion_started:
                    player_explosions.append([triangle_pos[0], triangle_pos[1], EXPLOSION_DURATION])
                    lives -= 1
                    if lives <= 0:
                        game_over = True
                        full_screen_explosion_started = True
                        full_screen_explosion_start_time = pygame.time.get_ticks()
                        break
                squares.remove(square)

        for bullet in bullets[:]:
            bullet[1] -= BULLET_SPEED
            if bullet[1] < 0:
                bullets.remove(bullet)
            else:
                for square in squares[:]:
                    if square[0] < bullet[0] < square[0] + 60 and square[1] < bullet[1] < square[1] + 60:
                        bullets.remove(bullet)
                        squares.remove(square)
                        explosions.append([square[0], square[1], EXPLOSION_DURATION])
                        destroyed_squares += 1

                        if destroyed_squares % BULLET_COUNT_THRESHOLD == 0:
                            if current_bullet_count < MAX_BULLETS:
                                current_bullet_count += 1
                            else:
                                current_bullet_count = 1
                                if bullet_size_increase_count < BULLET_SIZE_INCREASE_LIMIT:
                                    current_bullet_size += current_bullet_size * BULLET_SIZE_INCREASE_STEP
                                    bullet_size_increase_count += 1
                                else:
                                    bullet_size_increase_count = 0
                                    current_bullet_size = BULLET_RADIUS

                        break

        if len(squares) == 0 and len(explosions) == 0 and len(player_explosions) == 0:
            current_wave += 1
            if current_wave % WAVE_INCREASE_INTERVAL == 0:
                squares_in_wave += EXTRA_SQUARES_PER_WAVE

    # Отображение корабля вместо треугольника
    screen.blit(ship_image, (triangle_pos[0], triangle_pos[1]))

    # Отображение врагов вместо квадратов
    for square in squares:
        screen.blit(enemy_image, (square[0], square[1]))

    for bullet in bullets:
        draw_bullet(bullet)
    for explosion in explosions[:]:
        draw_explosion(explosion, explosion[2])
        explosion[2] -= 1
        if explosion[2] <= 0:
            explosions.remove(explosion)
    for explosion in player_explosions[:]:
        draw_explosion(explosion, explosion[2], player=True)
        explosion[2] -= 1
        if explosion[2] <= 0:
            player_explosions.remove(explosion)

    draw_score_and_lives()

else:
    draw_full_screen_explosion()
    if pygame.time.get_ticks() - full_screen_explosion_start_time >= FULL_EXPLOSION_TIME:
        screen.fill(WHITE)
        font = pygame.font.SysFont(None, 48)
        draw_text_with_outline("Вы проиграли!", font, WIDTH // 2 - 150, HEIGHT // 2 - 50)
        draw_text_with_outline("Нажмите R для перезапуска, Esc для выхода или C для очистки таблицы лидеров", 
                               font, WIDTH // 2 - 300, HEIGHT // 2 + 20)

        update_leaderboard(user_name, user_login, destroyed_squares)
        display_leaderboard()

for event in pygame.event.get():
    if event.type == QUIT:
        running = False
    elif event.type == KEYDOWN:
        if event.key == K_ESCAPE:
            running = False
        elif event.key == K_r:
            triangle_pos = [WIDTH // 2, HEIGHT - 60]
            squares = []
            bullets = []
            explosions = []
            player_explosions = []
            destroyed_squares = 0
            current_wave = 1
            squares_in_wave = SQUARES_PER_WAVE
            lives = INITIAL_LIVES
            game_over = False
            full_screen_explosion_started = False
            current_bullet_count = 1
            current_bullet_size = BULLET_RADIUS
            bullet_size_increase_count = 0
        elif event.key == pygame.K_c:
            clear_leaderboard()  # Очистка таблицы лидеров

pygame.display.flip()
clock.tick(60)
pygame.quit()
conn.close()