graphics.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:pool 作者: max-kov 项目源码 文件源码
def iterate_until_button_press(buttons, game_state, text_ending_place, text_starting_place):
    # while a button was not clicked this method checks if mouse is in the button and if it is
    # changes its colour
    button_clicked = 0
    while button_clicked == 0:
        pygame.display.update()
        user_events = event.events()
        # the first button is the title which is unclickable, thus iterating from 1 to len(buttons)
        for num in range(1, len(buttons)):
            if np.all((np.less(text_starting_place[num] - config.menu_spacing, user_events["mouse_pos"]),
                       np.greater(text_ending_place[num] + config.menu_spacing, user_events["mouse_pos"]))):
                if user_events["clicked"]:
                    button_clicked = num
                else:
                    game_state.canvas.surface.blit(
                        buttons[num][1], text_starting_place[num])
            else:
                game_state.canvas.surface.blit(
                    buttons[num][0], text_starting_place[num])
        if user_events["closed"] or user_events["quit_to_main_menu"]:
            button_clicked = len(buttons)-1
    return button_clicked
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号