def opening_screen(ai_settings, game_stats, screen): """Display the menu in the beginning""" # Set up screen attributes menu = Intro(ai_settings, game_stats, screen) play_button = Button(ai_settings, screen, 'Play Game', y_factor=0.70) hs_button = Button(ai_settings, screen, 'High Scores', y_factor=0.80) intro = True # Manages the key presses of the game while intro: for events in pygame.event.get(): if events.type == pygame.QUIT: return False elif events.type == pygame.MOUSEBUTTONDOWN: click_x, click_y = pygame.mouse.get_pos() game_stats.game_active = play_button.check_button(click_x, click_y) intro = not game_stats.game_active if hs_button.check_button(click_x, click_y): ret_hs = high_score_screen(ai_settings, screen) if not ret_hs: return False screen.fill(ai_settings.bg_color) # Allow the menu to display on the top layer menu.show_menu() # Draw the button on the main screen hs_button.draw_button() play_button.draw_button() # Display past pygame.display.flip() return True
def startup_screen(ai_settings, game_stats, screen): """Display the startup menu on the screen, return False if the user wishes to quit, True if they are ready to play""" menu = Intro(ai_settings, game_stats, screen) play_button = Button(ai_settings, screen, 'Play Game', y_factor=0.70) hs_button = Button(ai_settings, screen, 'High Scores', y_factor=0.80) intro = True while intro: play_button.alter_text_color(*pygame.mouse.get_pos()) hs_button.alter_text_color(*pygame.mouse.get_pos()) for event in pygame.event.get(): if event.type == pygame.QUIT: return False elif event.type == pygame.MOUSEBUTTONDOWN: click_x, click_y = pygame.mouse.get_pos() game_stats.game_active = play_button.check_button( click_x, click_y) intro = not game_stats.game_active if hs_button.check_button(click_x, click_y): ret_hs = high_score_screen(ai_settings, game_stats, screen) if not ret_hs: return False screen.fill(ai_settings.bg_color) menu.show_menu() hs_button.draw_button() play_button.draw_button() pygame.display.flip() return True
def high_score_screen(ai_settings, game_stats, screen): hs_screen = HighScoreScreen(ai_settings, screen, game_stats) back_button = Button(ai_settings, screen, 'Back To Menu', y_factor=0.85) while True: back_button.alter_text_color(*pygame.mouse.get_pos()) for event in pygame.event.get(): if event.type == pygame.QUIT: return False elif event.type == pygame.MOUSEBUTTONDOWN: if back_button.check_button(*pygame.mouse.get_pos()): return True screen.fill(ai_settings.bg_color) hs_screen.show_scores() back_button.draw_button() pygame.display.flip()
def startup_screen(config, game_stats, screen): """Display an introductory startup screen for the game, return False if the user wishes to quit, True if the user is ready to play""" title_screen = Intro(config, game_stats, screen) title_screen.prep_image() button = Button(config, screen, 'Play') intro = True while intro: for event in pygame.event.get(): if event.type == pygame.QUIT: return False elif event.type == pygame.MOUSEBUTTONDOWN: click_x, click_y = pygame.mouse.get_pos() game_stats.game_active = button.check_button(click_x, click_y) intro = not game_stats.game_active screen.fill(config.bg_color) title_screen.show_menu() button.draw_button() pygame.display.flip() return True
def high_score_screen(ai_settings, screen): """Display all high scores in a separate screen with a back button""" # Set the screen attributes hs_screen = HighScoreScreen(ai_settings, screen) back_button = Button(ai_settings, screen, 'Back To Menu', y_factor=0.85) while True: # Functions of the game when key presses touched for events in pygame.event.get(): if events.type == pygame.QUIT: return False elif events.type == pygame.MOUSEBUTTONDOWN: if back_button.check_button(*pygame.mouse.get_pos()): return True screen.fill(ai_settings.bg_color) # Allow to show the scores on the high score screen hs_screen.show_scores() # Redraw button back_button.draw_button() # Display past pygame.display.flip()
settings = Settings() pygame.init() screen = pygame.display.set_mode( (settings.screen_width, settings.screen_height)) pygame.display.set_caption('Centipede') all_sprites = Group() bullets = Group() # группа для хранения пуль mushrooms = Group() shooter_group = Group() logo = Group() gui = GUI() Label('name_game', logo, settings) Label('centipede', logo, settings) b1 = Button((settings.screen_width // 2 - 150, settings.screen_height // 2 - 100, 400, 100), 'start') b2 = Button((settings.screen_width // 2 - 150, settings.screen_height // 2 + 100, 400, 100), 'exit') gui.add_element(b1) gui.add_element(b2) centipede = Centipede([speed, 0], [300, 0], screen, 7) gf.make_mushrooms(settings, mushrooms, 15) shooter = Shooter(settings, screen) cursor = pygame.sprite.Sprite() cursor.image = pygame.transform.scale( pygame.image.load("./data/foto/arrow.png"), (50, 50)) cursor.rect = cursor.image.get_rect() shooter_group.add(shooter)