From 20089ccd0ecb00fca3249b9e810b840a0ceae75d Mon Sep 17 00:00:00 2001 From: Arseshka Lu Date: Sun, 3 Mar 2024 22:04:35 +0200 Subject: [PATCH] Music off/on --- .idea/Pygame_Project.iml | 2 +- .idea/misc.xml | 2 +- bla.py | 19 +++++++++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.idea/Pygame_Project.iml b/.idea/Pygame_Project.iml index 909438d..f571432 100644 --- a/.idea/Pygame_Project.iml +++ b/.idea/Pygame_Project.iml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index a6218fe..e73a553 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/bla.py b/bla.py index 023dca9..8ed184c 100644 --- a/bla.py +++ b/bla.py @@ -377,20 +377,29 @@ def draw_settings_menu(): quit_rect = quit_text.get_rect(topright=(SCREEN_WIDTH - 20, 20)) screen.blit(quit_text, quit_rect) + # Рисуем кнопку для управления музыкой + if pygame.mixer.music.get_busy(): + music_text = font.render("Music Off", True, WHITE) + else: + music_text = font.render("Music On", True, WHITE) + music_rect = music_text.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 - 100)) + screen.blit(music_text, music_rect) + pygame.display.flip() - return quit_rect + return quit_rect, music_rect # Главный цикл программы menu_active = True settings_active = False # Флаг, показывающий, активно ли меню настроек + while menu_active: if not settings_active: start_rect, settings_rect, quit_rect = draw_menu() else: - quit_rect = draw_settings_menu() + quit_rect, music_rect = draw_settings_menu() for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: @@ -406,6 +415,12 @@ while menu_active: else: if quit_rect.collidepoint(event.pos): settings_active = False + elif music_rect.collidepoint(event.pos): + if pygame.mixer.music.get_busy(): + pygame.mixer.music.stop() # Выключение музыки + else: + pygame.mixer.music.play(-1) # Включение музыки + # Основной игровой цикл clock = pygame.time.Clock()