import pygame import sys import math import subprocess # Initialize Pygame pygame.init() # Set the dimensions of the screen SCREEN_WIDTH = 800 SCREEN_HEIGHT = 800 screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) pygame.display.set_caption("Title Screen") # Load head images head_images = [ pygame.image.load("assets/Mr Marshall.png"), pygame.image.load("assets/Mr Turner.png"), pygame.image.load("assets/Mr Stuart.png"), pygame.image.load("assets/Mr Watson.png") ] # Load the title images title_image = pygame.image.load("assets/TitleText.png") title_image2 = pygame.image.load("assets/TitleText2.png") # Load the background image background_image = pygame.image.load("assets/background.png").convert() # Load other images play_button = pygame.image.load("assets/StartButton.png") play_button_hover = pygame.image.load("assets/StartButtonHover.png") # Define the initial positions of the head images image_positions = [ (0, SCREEN_HEIGHT - 250), (190, SCREEN_HEIGHT - 300), (360, SCREEN_HEIGHT - 300), (550, SCREEN_HEIGHT - 250) ] # Load the background music pygame.mixer.music.load("assets/BackgroundMusic.mp3") pygame.mixer.music.play(-1) pygame.mixer.music.set_volume(0.1) # Define the animation parameters tilt_angle = 5 tilt_speed = 0.005 pulse_speed = 0.002 pulse_amplitude = 0.09 # Function to check if a point is within a rectangle def is_mouse_over(rect): mouse_pos = pygame.mouse.get_pos() return rect.collidepoint(mouse_pos) # Main loop running = True while running: screen.fill((255, 255, 255)) # Draw the background image screen.blit(background_image, (0, 0)) # Check if the mouse is over the play button play_button_rect = play_button.get_rect(topleft=(250, 320)) if is_mouse_over(play_button_rect): screen.blit(play_button_hover, (250, 320)) scaled_play_button = pygame.transform.scale(play_button_hover, (int(play_button.get_width() * 1.1), int(play_button.get_height() * 1.1))) screen.blit(scaled_play_button, (240, 310)) else: screen.blit(play_button, (250, 320)) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False pygame.quit() sys.exit() elif event.type == pygame.MOUSEBUTTONDOWN: if is_mouse_over(play_button_rect): subprocess.Popen(["python", "lobby.py"]) # Calculate scale factor for pulsating effect scale_factor = 1.0 + pulse_amplitude * math.sin(pygame.time.get_ticks() * pulse_speed) # Draw title image with pulsating effect scaled_title_image = pygame.transform.scale(title_image, (int(title_image.get_width() * scale_factor), int(title_image.get_height() * scale_factor))) screen.blit(scaled_title_image, (SCREEN_WIDTH // 2 - scaled_title_image.get_width() // 2, 70)) scaled_title_image2 = pygame.transform.scale(title_image2, (int(title_image2.get_width() * scale_factor), int(title_image2.get_height() * scale_factor))) screen.blit(scaled_title_image2, (SCREEN_WIDTH // 2 - scaled_title_image2.get_width() // 2, 200)) # Head Image Animations for i, image in enumerate(head_images): angle = tilt_angle * math.sin(pygame.time.get_ticks() * tilt_speed + i * 0.5) rotated_image = pygame.transform.rotate(image, angle) rotated_rect = rotated_image.get_rect(center=image.get_rect(topleft=image_positions[i]).center) screen.blit(rotated_image, rotated_rect.topleft) pygame.display.flip() pygame.time.Clock().tick(30)