Music off/on

main
Arseshka Lu 2024-03-03 22:04:35 +02:00
parent 4692f38118
commit 20089ccd0e
3 changed files with 19 additions and 4 deletions

View File

@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.11" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -3,5 +3,5 @@
<component name="Black">
<option name="sdkName" value="Python 3.11" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
</project>

19
bla.py
View File

@ -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()