Обновить menu copy 2.py
parent
2bafedc81f
commit
eebc489d4f
268
menu copy 2.py
268
menu copy 2.py
|
@ -1,135 +1,135 @@
|
||||||
import pygame, sys
|
import pygame, sys
|
||||||
from button import Button
|
from button import Button
|
||||||
import pygame
|
import pygame
|
||||||
from random import randint
|
from random import randint
|
||||||
import math
|
import math
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
SCREEN = pygame.display.set_mode((1280, 720))
|
SCREEN = pygame.display.set_mode((1280, 720))
|
||||||
pygame.display.set_caption("Menu")
|
pygame.display.set_caption("Menu")
|
||||||
|
|
||||||
BG = pygame.image.load("assets/Background.png")
|
BG = pygame.image.load("assets/Background.png")
|
||||||
pygame.mixer.music.load('assets/Pixel 10.mp3')
|
pygame.mixer.music.load('assets/Pixel 7.mp3')
|
||||||
|
|
||||||
# Воспроизведение музыки
|
# Воспроизведение музыки
|
||||||
pygame.mixer.music.play()
|
pygame.mixer.music.play()
|
||||||
|
|
||||||
# Добавьте какую-то задержку, чтобы музыка воспроизводилась в течение некоторого времени
|
# Добавьте какую-то задержку, чтобы музыка воспроизводилась в течение некоторого времени
|
||||||
pygame.time.delay(5000) # Например, 5000 миллисекунд (5 секунд)
|
pygame.time.delay(5000) # Например, 5000 миллисекунд (5 секунд)
|
||||||
|
|
||||||
def get_font(size): # Returns Press-Start-2P in the desired size
|
def get_font(size): # Returns Press-Start-2P in the desired size
|
||||||
return pygame.font.Font("assets/font.ttf", size)
|
return pygame.font.Font("assets/font.ttf", size)
|
||||||
|
|
||||||
def play():
|
def play():
|
||||||
while True:
|
while True:
|
||||||
import Movement_version_3
|
import Movement_version_3
|
||||||
# Movement_version_3 vietāpievienojiet failu ar pabeigto spēli
|
# Movement_version_3 vietāpievienojiet failu ar pabeigto spēli
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def options():
|
def options():
|
||||||
volume = 1 # Initial volume
|
volume = 1 # Initial volume
|
||||||
slider_height = 20 # Slider height
|
slider_height = 20 # Slider height
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
SCREEN.blit(BG, (0, 0))
|
SCREEN.blit(BG, (0, 0))
|
||||||
OPTIONS_MOUSE_POS = pygame.mouse.get_pos()
|
OPTIONS_MOUSE_POS = pygame.mouse.get_pos()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OPTIONS_TEXT = get_font(45).render("Change Volume", True, "white")
|
OPTIONS_TEXT = get_font(45).render("Change Volume", True, "white")
|
||||||
OPTIONS_RECT = OPTIONS_TEXT.get_rect(center=(640, 260))
|
OPTIONS_RECT = OPTIONS_TEXT.get_rect(center=(640, 260))
|
||||||
SCREEN.blit(OPTIONS_TEXT, OPTIONS_RECT)
|
SCREEN.blit(OPTIONS_TEXT, OPTIONS_RECT)
|
||||||
|
|
||||||
# Volume slider
|
# Volume slider
|
||||||
|
|
||||||
pygame.draw.rect(SCREEN, "gray", (500, 330, 200, slider_height)) # Slider background
|
pygame.draw.rect(SCREEN, "gray", (500, 330, 200, slider_height)) # Slider background
|
||||||
|
|
||||||
# Calculate slider width based on volume level
|
# Calculate slider width based on volume level
|
||||||
slider_width = int(volume * 200)
|
slider_width = int(volume * 200)
|
||||||
slider_color = (62, 74, 49) # Green color
|
slider_color = (62, 74, 49) # Green color
|
||||||
if volume < 1:
|
if volume < 1:
|
||||||
slider_color = (0, 255 * (1 - volume), 0) # Decrease green component based on volume level
|
slider_color = (0, 255 * (1 - volume), 0) # Decrease green component based on volume level
|
||||||
pygame.draw.rect(SCREEN, slider_color, (500, 330, slider_width, slider_height)) # Actual slider
|
pygame.draw.rect(SCREEN, slider_color, (500, 330, slider_width, slider_height)) # Actual slider
|
||||||
|
|
||||||
# Draw "+" and "-" symbols
|
# Draw "+" and "-" symbols
|
||||||
plus_text = get_font(30).render("+", True, "#5c3938")
|
plus_text = get_font(30).render("+", True, "#5c3938")
|
||||||
minus_text = get_font(30).render("-", True, "#5c3938")
|
minus_text = get_font(30).render("-", True, "#5c3938")
|
||||||
plus_rect = plus_text.get_rect(center=(715, 330 + slider_height // 2))
|
plus_rect = plus_text.get_rect(center=(715, 330 + slider_height // 2))
|
||||||
minus_rect = minus_text.get_rect(center=(485, 330 + slider_height // 2))
|
minus_rect = minus_text.get_rect(center=(485, 330 + slider_height // 2))
|
||||||
SCREEN.blit(plus_text, plus_rect)
|
SCREEN.blit(plus_text, plus_rect)
|
||||||
SCREEN.blit(minus_text, minus_rect)
|
SCREEN.blit(minus_text, minus_rect)
|
||||||
|
|
||||||
# BACK button
|
# BACK button
|
||||||
OPTIONS_BACK = Button(image=None, pos=(640, 460),
|
OPTIONS_BACK = Button(image=None, pos=(640, 460),
|
||||||
text_input="BACK", font=get_font(75), base_color="#5c3938", hovering_color="White")
|
text_input="BACK", font=get_font(75), base_color="#5c3938", hovering_color="White")
|
||||||
|
|
||||||
OPTIONS_BACK.changeColor(OPTIONS_MOUSE_POS)
|
OPTIONS_BACK.changeColor(OPTIONS_MOUSE_POS)
|
||||||
OPTIONS_BACK.update(SCREEN)
|
OPTIONS_BACK.update(SCREEN)
|
||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
if OPTIONS_BACK.checkForInput(OPTIONS_MOUSE_POS):
|
if OPTIONS_BACK.checkForInput(OPTIONS_MOUSE_POS):
|
||||||
main_menu()
|
main_menu()
|
||||||
# Check if mouse click is on minus symbol
|
# Check if mouse click is on minus symbol
|
||||||
if minus_rect.collidepoint(event.pos):
|
if minus_rect.collidepoint(event.pos):
|
||||||
volume -= 0.1
|
volume -= 0.1
|
||||||
if volume < 0:
|
if volume < 0:
|
||||||
volume = 0
|
volume = 0
|
||||||
pygame.mixer.music.set_volume(volume) # Set the volume of the music
|
pygame.mixer.music.set_volume(volume) # Set the volume of the music
|
||||||
# Check if mouse click is on plus symbol
|
# Check if mouse click is on plus symbol
|
||||||
if plus_rect.collidepoint(event.pos):
|
if plus_rect.collidepoint(event.pos):
|
||||||
volume += 0.1
|
volume += 0.1
|
||||||
if volume > 1:
|
if volume > 1:
|
||||||
volume = 1
|
volume = 1
|
||||||
pygame.mixer.music.set_volume(volume) # Set the volume of the music
|
pygame.mixer.music.set_volume(volume) # Set the volume of the music
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main_menu():
|
def main_menu():
|
||||||
while True:
|
while True:
|
||||||
SCREEN.blit(BG, (0, 0))
|
SCREEN.blit(BG, (0, 0))
|
||||||
|
|
||||||
MENU_MOUSE_POS = pygame.mouse.get_pos()
|
MENU_MOUSE_POS = pygame.mouse.get_pos()
|
||||||
|
|
||||||
MENU_TEXT = get_font(100).render("Roguelite", True, "white")
|
MENU_TEXT = get_font(100).render("Roguelite", True, "white")
|
||||||
MENU_RECT = MENU_TEXT.get_rect(center=(640, 100))
|
MENU_RECT = MENU_TEXT.get_rect(center=(640, 100))
|
||||||
|
|
||||||
PLAY_BUTTON = Button(image=pygame.image.load("assets/Play Rect.png"), pos=(640, 250),
|
PLAY_BUTTON = Button(image=pygame.image.load("assets/Play Rect.png"), pos=(640, 250),
|
||||||
text_input="PLAY", font=get_font(75), base_color="#5c3938", hovering_color="White")
|
text_input="PLAY", font=get_font(75), base_color="#5c3938", hovering_color="White")
|
||||||
OPTIONS_BUTTON = Button(image=pygame.image.load("assets/Options Rect.png"), pos=(640, 400),
|
OPTIONS_BUTTON = Button(image=pygame.image.load("assets/Options Rect.png"), pos=(640, 400),
|
||||||
text_input="OPTIONS", font=get_font(75), base_color="#5c3938", hovering_color="White")
|
text_input="OPTIONS", font=get_font(75), base_color="#5c3938", hovering_color="White")
|
||||||
QUIT_BUTTON = Button(image=pygame.image.load("assets/Quit Rect.png"), pos=(640, 550),
|
QUIT_BUTTON = Button(image=pygame.image.load("assets/Quit Rect.png"), pos=(640, 550),
|
||||||
text_input="QUIT", font=get_font(75), base_color="#5c3938", hovering_color="White")
|
text_input="QUIT", font=get_font(75), base_color="#5c3938", hovering_color="White")
|
||||||
|
|
||||||
SCREEN.blit(MENU_TEXT, MENU_RECT)
|
SCREEN.blit(MENU_TEXT, MENU_RECT)
|
||||||
|
|
||||||
for button in [PLAY_BUTTON, OPTIONS_BUTTON, QUIT_BUTTON]:
|
for button in [PLAY_BUTTON, OPTIONS_BUTTON, QUIT_BUTTON]:
|
||||||
button.changeColor(MENU_MOUSE_POS)
|
button.changeColor(MENU_MOUSE_POS)
|
||||||
button.update(SCREEN)
|
button.update(SCREEN)
|
||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
if PLAY_BUTTON.checkForInput(MENU_MOUSE_POS):
|
if PLAY_BUTTON.checkForInput(MENU_MOUSE_POS):
|
||||||
play()
|
play()
|
||||||
if OPTIONS_BUTTON.checkForInput(MENU_MOUSE_POS):
|
if OPTIONS_BUTTON.checkForInput(MENU_MOUSE_POS):
|
||||||
options()
|
options()
|
||||||
if QUIT_BUTTON.checkForInput(MENU_MOUSE_POS):
|
if QUIT_BUTTON.checkForInput(MENU_MOUSE_POS):
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
main_menu()
|
main_menu()
|
Loading…
Reference in New Issue