Update Gaame with menu
parent
c0d65c7c1a
commit
a40b5b84a6
|
@ -261,6 +261,8 @@ bot = Bot(3 * SCREEN_WIDTH // 4, SCREEN_HEIGHT // 2)
|
||||||
all_sprites.add(bot)
|
all_sprites.add(bot)
|
||||||
tanks.add(bot)
|
tanks.add(bot)
|
||||||
|
|
||||||
|
music_enabled = True
|
||||||
|
|
||||||
def draw_menu():
|
def draw_menu():
|
||||||
screen.blit(menu_background, (0, 0))
|
screen.blit(menu_background, (0, 0))
|
||||||
# Рисуем текст меню
|
# Рисуем текст меню
|
||||||
|
@ -274,9 +276,31 @@ def draw_menu():
|
||||||
quit_rect = quit_text.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 + 50))
|
quit_rect = quit_text.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 + 50))
|
||||||
screen.blit(quit_text, quit_rect)
|
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()
|
pygame.display.flip()
|
||||||
|
|
||||||
return quit_rect # Возвращаем прямоугольник для кнопки "Выйти"
|
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() # Выключаем музыку
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -503,10 +527,9 @@ while running:
|
||||||
screen.blit(stenki, (1600, 1030))
|
screen.blit(stenki, (1600, 1030))
|
||||||
screen.blit(stenki, (1800, 1030))
|
screen.blit(stenki, (1800, 1030))
|
||||||
|
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
clock.tick(FPS)
|
clock.tick(FPS)
|
||||||
|
|
||||||
# Завершение работы Pygame
|
# Завершение работы Pygame
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
|
||||||
# token: 8f195a885b18a96da6577884cc731f850f33a9e2 переделай код так чтоби игру мозно било приостанавливат кнопкой escape
|
|
Loading…
Reference in New Issue