parent
deb24245fb
commit
770715964a
53
bla.py
53
bla.py
|
@ -2,6 +2,8 @@ import pygame
|
|||
import random
|
||||
import math
|
||||
|
||||
from main import current_time
|
||||
|
||||
# Определение констант
|
||||
SCREEN_WIDTH = 1920
|
||||
SCREEN_HEIGHT = 1080
|
||||
|
@ -18,7 +20,6 @@ FIRE_DELAY = 1000 # Задержка между выстрелами в мил
|
|||
WHITE = (255, 255, 255)
|
||||
BLACK = (0, 0, 0)
|
||||
score = 0
|
||||
|
||||
# Инициализация Pygame
|
||||
pygame.init()
|
||||
|
||||
|
@ -48,9 +49,12 @@ menu_background = pygame.transform.scale(pygame.image.load("menu_background.jpg"
|
|||
|
||||
cursor = pygame.image.load("cursor.png")
|
||||
pygame.mouse.set_visible(False)
|
||||
|
||||
cursor_offset_x = cursor.get_width() // 2
|
||||
cursor_offset_y = cursor.get_height() // 2
|
||||
|
||||
paused_menu_active = False
|
||||
|
||||
class Explosion(pygame.sprite.Sprite):
|
||||
def __init__(self, x, y):
|
||||
super().__init__()
|
||||
|
@ -456,14 +460,53 @@ while running:
|
|||
elif event.key == pygame.K_ESCAPE:
|
||||
# Toggle pause state when escape key is pressed
|
||||
paused = not paused
|
||||
elif event.key == pygame.K_SPACE:
|
||||
# Return to menu when space key is pressed
|
||||
menu_active = True
|
||||
settings_active = False # Reset settings_active when returning to menu
|
||||
|
||||
if not paused: # If not paused, update game state
|
||||
if menu_active: # If in menu, return to menu loop
|
||||
while menu_active:
|
||||
start_rect, settings_rect, quit_rect = draw_menu()
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||
if event.button == 1: # Left mouse button
|
||||
if start_rect.collidepoint(event.pos):
|
||||
menu_active = False # Start button clicked
|
||||
elif settings_rect.collidepoint(event.pos):
|
||||
settings_active = True # Settings button clicked
|
||||
menu_active = False # Return to menu loop
|
||||
elif quit_rect.collidepoint(event.pos):
|
||||
pygame.quit()
|
||||
quit()
|
||||
pygame.display.flip() # Update the display
|
||||
clock.tick(FPS) # Limit the frame rate
|
||||
|
||||
elif settings_active: # If in settings, return to settings loop
|
||||
while settings_active:
|
||||
quit_rect, music_rect = draw_settings_menu()
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||
if event.button == 1: # Left mouse button
|
||||
if quit_rect.collidepoint(event.pos):
|
||||
menu_active = True # Set menu_active to True to return to menu
|
||||
settings_active = False # Quit button clicked
|
||||
draw_menu() # Redraw the menu to prevent flickering
|
||||
elif music_rect.collidepoint(event.pos):
|
||||
if pygame.mixer.music.get_busy():
|
||||
pygame.mixer.music.stop() # Turn off music
|
||||
else:
|
||||
pygame.mixer.music.play(-1) # Turn on music
|
||||
pygame.display.flip() # Update the display
|
||||
clock.tick(FPS) # Limit the frame rate
|
||||
|
||||
|
||||
elif not paused: # If not in menu and not paused, update game state
|
||||
# Update sprites
|
||||
x, y = pygame.mouse.get_pos()
|
||||
screen.blit(cursor, (x - cursor_offset_x, y - cursor_offset_y))
|
||||
|
||||
all_sprites.update()
|
||||
|
||||
|
||||
|
||||
# Проверка столкновений пуль с танками
|
||||
for bullet in bullets:
|
||||
if isinstance(bullet, PlayerBullet):
|
||||
|
|
Loading…
Reference in New Issue