def update_game(): """ Update the game's UI. """ to_draw = [] draw_parameters = a1_game.update_ui() p1_sprite = draw_parameters['p1_sprite'] p1_hp = draw_parameters['p1_hp'] p1_sp = draw_parameters['p1_sp'] p1_name = draw_parameters['p1_name'] p1_label = ("{}\nHP: {}\nSP: {}\nSprite: {}".format(p1_name, p1_hp, p1_sp, p1_sprite)) to_draw.append(p1_label) p2_sprite = draw_parameters['p2_sprite'] p2_hp = draw_parameters['p2_hp'] p2_sp = draw_parameters['p2_sp'] p2_name = draw_parameters['p2_name'] p2_label = ("{}\nHP: {}\nSP: {}\nSprite: {}".format(p2_name, p2_hp, p2_sp, p2_sprite)) to_draw.append(p2_label) # Update the current player and available actions if not a1_game.GAME_IS_OVER: actions = draw_parameters['actions'] current_player = draw_parameters['current_player'] action_label = ["Current Character: {}".format(current_player), "Available Actions: {}".format(", ".join(actions))] to_draw.append("\n".join(action_label)) else: game_label = ["Game over!"] winner = a1_game.GAME_WINNER if winner: game_label.append("The winner is {}!".format(winner.get_name())) else: game_label.append("The game ended in a tie!") to_draw.append("\n".join(game_label)) print("\n".join(to_draw)) print("-" * 20)
def update_game(): """ Update the game's UI. """ global PYGAME_SCREEN, CHARACTER_SIZE, P1_POSITION, P2_POSITION draw_parameters = a1_game.update_ui() p1_sprite = draw_parameters['p1_sprite'] p1_hp = draw_parameters['p1_hp'] p1_sp = draw_parameters['p1_sp'] p1_name = draw_parameters['p1_name'] p1_label = "{}\nHP: {}\nSP: {}".format(p1_name, p1_hp, p1_sp).split("\n") p2_sprite = draw_parameters['p2_sprite'] p2_hp = draw_parameters['p2_hp'] p2_sp = draw_parameters['p2_sp'] p2_name = draw_parameters['p2_name'] p2_label = "{}\nHP: {}\nSP: {}".format(p2_name, p2_hp, p2_sp).split("\n") font_type = pygame.font.get_default_font() font = pygame.font.SysFont(font_type, FONT_SIZE) p1_icon = pygame.image.load('sprites/' + p1_sprite + '.png') p2_icon = pygame.image.load('sprites/' + p2_sprite + '.png') PYGAME_SCREEN.fill((255, 255, 255)) # (255, 255, 255)=(r,g,b)=white bg = pygame.image.load('sprites/background.png') rect = pygame.Rect(0, 0, NUMBER_OF_CHARACTERS * CHARACTER_SIZE, CHARACTER_SIZE + PADDING * 2) PYGAME_SCREEN.blit(bg, rect) # Draw the first character (x, y) = P1_POSITION, PADDING rect = pygame.Rect(x, y, CHARACTER_SIZE, CHARACTER_SIZE) PYGAME_SCREEN.blit(p1_icon, rect) y_coordinate = 0 for line in p1_label: text = font.render(line, True, (0, 0, 0)) PYGAME_SCREEN.blit(text, (P1_POSITION + PADDING, y_coordinate)) y_coordinate += FONT_SIZE # Draw the HP bar # Draw the SP bar # Draw the second character # Flip p2 so they face p1 p2_icon = pygame.transform.flip(p2_icon, True, False) (x, y) = P2_POSITION, PADDING rect = pygame.Rect(x, y, CHARACTER_SIZE, CHARACTER_SIZE) PYGAME_SCREEN.blit(p2_icon, rect) y_coordinate = 0 for line in p2_label: text = font.render(line, True, (0, 0, 0)) PYGAME_SCREEN.blit(text, (P2_POSITION + PADDING, y_coordinate)) y_coordinate += FONT_SIZE # Update the current player and available actions if not a1_game.GAME_IS_OVER: actions = draw_parameters['actions'] current_player = draw_parameters['current_player'] action_label = ["Current Character: {}".format(current_player), "Available Actions: {}".format(", ".join(actions))] y_coordinate = CHARACTER_SIZE + PADDING for line in action_label: text = font.render(line, True, (0, 0, 0)) PYGAME_SCREEN.blit(text, (P1_POSITION + PADDING // 2, y_coordinate)) y_coordinate += FONT_SIZE else: game_label = ["Game over!"] winner = a1_game.GAME_WINNER if winner: game_label.append("The winner is {}!".format(winner.get_name())) else: game_label.append("The game ended in a tie!") y_coordinate = CHARACTER_SIZE + PADDING for line in game_label: text = font.render(line, True, (0, 0, 0)) PYGAME_SCREEN.blit(text, (P1_POSITION + PADDING // 2, y_coordinate)) y_coordinate += FONT_SIZE pygame.display.flip()