"""Main menu screen - title label and Play/Quit navigation.""" import sys import pygame_gui as pgi import pygame as pg from game.screens.base_screen import BaseScreen class MainMenu(BaseScreen): """The main menu screen with a title, Play button, and Quit button. Attributes: title (pgi.elements.UILabel): The menu title label. play_button (pgi.elements.UIButton): Transitions to the gameplay screen. quit_button (pgi.elements.UIButton): Exits the application. """ def __init__(self, game): super().__init__(game) manager = game.ui_manager width, height = pg.display.get_surface().get_size() # Größen title_width = 400 title_height = 80 button_width = 250 button_height = 60 center_x = width // 2 self.title = pgi.elements.UILabel( relative_rect=pg.Rect( center_x - title_width // 2, int(height * 0.2), title_width, title_height ), text="MAIN MENU", manager=manager ) self.play_button = pgi.elements.UIButton( relative_rect=pg.Rect( center_x - button_width // 2, int(height * 0.35), button_width, button_height ), text="Play", manager=manager ) self.quit_button = pgi.elements.UIButton( relative_rect=pg.Rect( center_x - button_width // 2, int(height * 0.60), button_width, button_height ), text="Quit", manager=manager ) self.elements = [ self.title, self.play_button, self.quit_button ] def process_event(self, event): """Handle Play and Quit button presses. Args: event (pg.event.Event): The pygame event to process. """ if event.type == pgi.UI_BUTTON_PRESSED: if event.ui_element == self.play_button: # Zum Gameplay wechseln self.game.change_screen("game") if event.ui_element == self.quit_button: pg.quit() sys.exit()