Update Gaame with menu
parent
a40b5b84a6
commit
da2edc7634
|
@ -261,8 +261,6 @@ bot = Bot(3 * SCREEN_WIDTH // 4, SCREEN_HEIGHT // 2)
|
|||
all_sprites.add(bot)
|
||||
tanks.add(bot)
|
||||
|
||||
music_enabled = True
|
||||
|
||||
def draw_menu():
|
||||
screen.blit(menu_background, (0, 0))
|
||||
# Рисуем текст меню
|
||||
|
@ -276,31 +274,9 @@ def draw_menu():
|
|||
quit_rect = quit_text.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 + 50))
|
||||
screen.blit(quit_text, quit_rect)
|
||||
|
||||
# Рисуем кнопку включения/выключения музыки
|
||||
music_text = font.render("Music: " + ("On" if music_enabled else "Off"), True, WHITE)
|
||||
music_rect = music_text.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 + 150))
|
||||
screen.blit(music_text, music_rect)
|
||||
|
||||
pygame.display.flip()
|
||||
|
||||
return quit_rect, music_rect # Возвращаем прямоугольники для кнопок "Выйти" и "Музыка"
|
||||
|
||||
# Главный цикл программы
|
||||
menu_active = True
|
||||
while menu_active:
|
||||
quit_rect, music_rect = draw_menu()
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||
if event.button == 1: # Левая кнопка мыши
|
||||
if quit_rect.collidepoint(event.pos):
|
||||
pygame.quit()
|
||||
quit()
|
||||
elif music_rect.collidepoint(event.pos): # Проверяем, нажата ли кнопка музыки
|
||||
music_enabled = not music_enabled # Инвертируем состояние звука
|
||||
if music_enabled:
|
||||
pygame.mixer.music.unpause() # Включаем музыку
|
||||
else:
|
||||
pygame.mixer.music.pause() # Выключаем музыку
|
||||
return quit_rect # Возвращаем прямоугольник для кнопки "Выйти"
|
||||
|
||||
|
||||
|
||||
|
@ -527,7 +503,6 @@ while running:
|
|||
screen.blit(stenki, (1600, 1030))
|
||||
screen.blit(stenki, (1800, 1030))
|
||||
|
||||
|
||||
pygame.display.flip()
|
||||
clock.tick(FPS)
|
||||
|
||||
|
|
Loading…
Reference in New Issue