import sys import pygame from common.colors import WHITE, FONT_DARK from common.helpers import draw_text from ui.screens.credits import Credits from ui.screens.options import Options from ui.screens.screen import Screen class MainMenu(Screen): def __init__(self, screen, clock, bg, btn_play_action, btn_options_action, btn_credits_action): super().__init__('main_menu', screen, clock) self.click = False self.bg = bg self.btn_play_action = btn_play_action self.btn_options_action = btn_options_action self.btn_credits_action = btn_credits_action def display_screen(self): running = True while running: self.screen.blit(self.bg, (0, 0)) pygame.draw.rect(self.screen, (255, 255, 255), pygame.Rect(800, 100, 400, 500), 0, 5) draw_text('MAIN MENU', FONT_DARK, self.screen, 850, 150, 30, True) mx, my = pygame.mouse.get_pos() button_1 = pygame.Rect(850, 250, 300, 50) button_2 = pygame.Rect(850, 350, 300, 50) button_3 = pygame.Rect(850, 450, 300, 50) if button_1.collidepoint((mx, my)): if self.click: self.btn_play_action() if button_2.collidepoint((mx, my)): if self.click: self.btn_options_action() if button_3.collidepoint((mx, my)): if self.click: self.btn_credits_action() pygame.draw.rect(self.screen, (0, 191, 255), button_1, 0, 4) draw_text('PLAY', WHITE, self.screen, 870, 255) pygame.draw.rect(self.screen, (0, 191, 255), button_2, 0, 4) draw_text('OPTIONS', WHITE, self.screen, 870, 355) pygame.draw.rect(self.screen, (0, 191, 255), button_3, 0, 4) draw_text('CREDITS', WHITE, self.screen, 870, 455) self.click = False for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: pygame.quit() sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: self.click = True pygame.display.update() self.clock.tick(60)