def intro_loop(): done = False text_font = pygame.font.SysFont('Arial', c.EXTRA_LARGE_TEXT) button_font = pygame.font.SysFont('Arial', c.LARGE_TEXT) start_button = Button( (c.SCREEN_WIDTH / 2 - c.LARGE_BUTTON_WIDTH / 2, c.SCREEN_HEIGHT / 2 + c.EXTRA_LARGE_TEXT, c.LARGE_BUTTON_WIDTH, c.LARGE_BUTTON_HEIGHT), 'Start', button_font, c.GRAY, c.HOT_PINK) start_button.assign_function(game_loop) button_sprites.add(start_button) while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: exit_game() for button in button_sprites: button.handle_event(event) screen.fill(c.WHITE) draw_text(screen, 'Welcome to the Game', text_font, [c.SCREEN_WIDTH / 2, c.SCREEN_HEIGHT / 2]) button_sprites.update() button_sprites.draw(screen) pygame.display.update()
def game_over_loop(): button_sprites.empty() done = False text_font = pygame.font.SysFont('Arial', c.EXTRA_LARGE_TEXT) button_font = pygame.font.SysFont('Arial', c.MEDIUM_TEXT) retry_button = Button( (c.SCREEN_WIDTH / 2, c.SCREEN_HEIGHT / 2 + c.LARGE_BUTTON_HEIGHT, c.LARGE_BUTTON_WIDTH, c.LARGE_BUTTON_HEIGHT), 'Restart', button_font, c.GRAY, c.LIGHT_STEEL_BLUE) retry_button.assign_function(restart_game) button_sprites.add(retry_button) while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: exit_game() for button in button_sprites: button.handle_event(event) screen.fill(c.WHITE) draw_text(screen, 'Congrats You Won!!', text_font, (c.SCREEN_WIDTH / 2, c.SCREEN_HEIGHT / 2)) button_sprites.update() button_sprites.draw(screen) pygame.display.update()
def create_buttons(stages): font = pygame.font.SysFont('Arial', c.SMALL_TEXT) margin = 10 button_area = margin + c.MEDIUM_BUTTON_WIDTH + margin y = 300 x = margin + c.SCREEN_WIDTH / 2 - (button_area * 3) / 2 check_button = Button( (x, y, c.MEDIUM_BUTTON_WIDTH, c.MEDIUM_BUTTON_HEIGHT), 'Check', font, c.GRAY, c.TAN) check_button.assign_function(progress_to_next_stage, stages) button_sprites.add(check_button) x += button_area clear_button = Button( (x, y, c.MEDIUM_BUTTON_WIDTH, c.MEDIUM_BUTTON_HEIGHT), 'Clear', font, c.GRAY, c.LIGHT_SKY_BLUE) clear_button.assign_function(reset) button_sprites.add(clear_button) x += button_area restart_button = Button( (x, y, c.MEDIUM_BUTTON_WIDTH, c.MEDIUM_BUTTON_HEIGHT), 'Restart', font, c.GRAY, c.ORCHID) restart_button.assign_function(restart_game) button_sprites.add(restart_button)