#this function was adapted from a post made by user SpoonMeiser at stackoverflow:
#https://stackoverflow.com/questions/49432109/how-to-wrap-text-in-pygame-using-pygame-font-font

def renderTextCenteredAt(text, font, colour, x, y, screen, allowed_width):
    # first, split the text into words
    words = text.split()

    # now, construct lines out of these words
    lines = []
    while len(words) > 0:
        # get as many words as will fit within allowed_width
        line_words = []
        while len(words) > 0:
            line_words.append(words.pop(0))
            fw, fh = font.size(' '.join(line_words + words[:1]))
            if fw > allowed_width:
                break

        # add a line consisting of those words
        line = ' '.join(line_words)
        lines.append(line)

    # now we've split our text into lines that fit into the width, actually
    # render them

    # we'll render each line below the last, so we need to keep track of
    # the culmative height of the lines we've rendered so far
    y_offset = 0
    ty = y
    for line in lines:
        fw, fh = font.size(line)

        # (tx, ty) is the top-left of the font surface
        tx = x - fw / 2
        font_surface = font.render(line, True, colour)
        screen.blit(font_surface, (tx, ty))
        ty = ty + fh

17e47219a92524cf378d55061a19cebd7a4f3d31
<mask token>

def renderTextCenteredAt(text, font, colour, x, y, screen, allowed_width):
    words = text.split()
    lines = []
    while len(words) > 0:
        line_words = []
        while len(words) > 0:
            line_words.append(words.pop(0))
            fw, fh = font.size(' '.join(line_words + words[:1]))
            if fw > allowed_width:
                break
        line = ' '.join(line_words)
        lines.append(line)
    y_offset = 0
    ty = y
    for line in lines:
        fw, fh = font.size(line)
        tx = x - fw / 2
        font_surface = font.render(line, True, colour)
        screen.blit(font_surface, (tx, ty))
        ty = ty + fh

#this function was adapted from a post made by user SpoonMeiser at stackoverflow:
#https://stackoverflow.com/questions/49432109/how-to-wrap-text-in-pygame-using-pygame-font-font

def renderTextCenteredAt(text, font, colour, x, y, screen, allowed_width):
    # first, split the text into words
    words = text.split()

    # now, construct lines out of these words
    lines = []
    while len(words) > 0:
        # get as many words as will fit within allowed_width
        line_words = []
        while len(words) > 0:
            line_words.append(words.pop(0))
            fw, fh = font.size(' '.join(line_words + words[:1]))
            if fw > allowed_width:
                break

        # add a line consisting of those words
        line = ' '.join(line_words)
        lines.append(line)

    # now we've split our text into lines that fit into the width, actually
    # render them

    # we'll render each line below the last, so we need to keep track of
    # the culmative height of the lines we've rendered so far
    y_offset = 0
    ty = y
    for line in lines:
        fw, fh = font.size(line)

        # (tx, ty) is the top-left of the font surface
        tx = x - fw / 2
        font_surface = font.render(line, True, colour)
        screen.blit(font_surface, (tx, ty))
        ty = ty + fh
