Game/menu copy 2.py

149 lines
5.6 KiB
Python

import pygame
import sys
from button import Button # Assuming you have a Button class defined in a separate file
from random import randint
import math
pygame.init()
SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720
SCREEN = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Rouglite")
# Loading images and music
BG = pygame.image.load("assets/Background.png")
LD = pygame.transform.scale(pygame.image.load("Sprites/loading.png").convert(), (SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.mixer.music.load('assets/Pixel 7.mp3')
# Define fonts
def get_font(size): # Returns Press-Start-2P in the desired size
return pygame.font.Font("assets/font.ttf", size)
def show_loading_screen():
start_time = pygame.time.get_ticks()
loading_image_rect = LD.get_rect(center=(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2))
pygame.mouse.set_visible(False) # Hide the cursor
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
SCREEN.fill((0, 0, 0))
SCREEN.blit(LD, loading_image_rect) # Display the loading image
pygame.display.update()
if pygame.time.get_ticks() - start_time >= 5000:
pygame.mouse.set_visible(True) # Show the cursor
return
# Display loading screen for 5 seconds before showing main menu
show_loading_screen()
def play():
while True:
pygame.time.delay(500)
import Game_V2
# Game_V2 vietāpievienojiet failu ar pabeigto spēli
def options():
volume = 1 # Initial volume
slider_height = 20 # Slider height
while True:
SCREEN.blit(BG, (0, 0))
OPTIONS_MOUSE_POS = pygame.mouse.get_pos()
OPTIONS_TEXT = get_font(45).render("Change Volume", True, "white")
OPTIONS_RECT = OPTIONS_TEXT.get_rect(center=(640, 260))
SCREEN.blit(OPTIONS_TEXT, OPTIONS_RECT)
# Volume slider
pygame.draw.rect(SCREEN, "gray", (500, 330, 200, slider_height)) # Slider background
# Calculate slider width based on volume level
slider_width = int(volume * 200)
slider_color = (62, 74, 49) # Green color
if volume < 1:
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
# Draw "+" and "-" symbols
plus_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))
minus_rect = minus_text.get_rect(center=(485, 330 + slider_height // 2))
SCREEN.blit(plus_text, plus_rect)
SCREEN.blit(minus_text, minus_rect)
# BACK button
OPTIONS_BACK = Button(image=None, pos=(640, 460),
text_input="BACK", font=get_font(75), base_color="#5c3938", hovering_color="White")
OPTIONS_BACK.changeColor(OPTIONS_MOUSE_POS)
OPTIONS_BACK.update(SCREEN)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if OPTIONS_BACK.checkForInput(OPTIONS_MOUSE_POS):
main_menu()
# Check if mouse click is on minus symbol
if minus_rect.collidepoint(event.pos):
volume -= 0.1
if volume < 0:
volume = 0
pygame.mixer.music.set_volume(volume) # Set the volume of the music
# Check if mouse click is on plus symbol
if plus_rect.collidepoint(event.pos):
volume += 0.1
if volume > 1:
volume = 1
pygame.mixer.music.set_volume(volume) # Set the volume of the music
pygame.display.update()
def main_menu():
while True:
SCREEN.blit(BG, (0, 0))
MENU_MOUSE_POS = pygame.mouse.get_pos()
MENU_TEXT = get_font(100).render("Roguelite", True, "white")
MENU_RECT = MENU_TEXT.get_rect(center=(640, 100))
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")
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")
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")
SCREEN.blit(MENU_TEXT, MENU_RECT)
for button in [PLAY_BUTTON, OPTIONS_BUTTON, QUIT_BUTTON]:
button.changeColor(MENU_MOUSE_POS)
button.update(SCREEN)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if PLAY_BUTTON.checkForInput(MENU_MOUSE_POS):
play()
if OPTIONS_BUTTON.checkForInput(MENU_MOUSE_POS):
options()
if QUIT_BUTTON.checkForInput(MENU_MOUSE_POS):
pygame.quit()
sys.exit()
pygame.display.update()
main_menu()