Esempio n. 1
0
 def run(self, game):
     util.render_text(self, dropper_locale.HOW_TO_PLAY_TITLE, (200, 100),
                      50)
     util.render_text(self, dropper_locale.HOW_TO_PLAY_LINE_1, (200, 200),
                      25)
     util.render_text(self, dropper_locale.HOW_TO_PLAY_LINE_2, (200, 225),
                      25)
     util.render_text(self, dropper_locale.HOW_TO_PLAY_LINE_3, (200, 250),
                      25)
     util.render_text(self, dropper_locale.HOW_TO_PLAY_GO_BACK, (200, 300),
                      25)
Esempio n. 2
0
 def run(self, game):
     util.render_text(self, dropper_locale.END_GAME_TITLE, (200, 100), 50)
     util.render_text(self,
                      dropper_locale.END_GAME_SCORE.format(game.score),
                      (200, 200), 25)
     util.render_text(
         self, dropper_locale.END_GAME_HIGH_SCORE.format(game.high_score),
         (200, 230), 25)
     util.render_text(self, dropper_locale.END_GAME_PLAY_AGAIN, (200, 300))
     util.render_text(self, dropper_locale.END_GAME_RETURN_TO_MENU,
                      (200, 350))
Esempio n. 3
0
    def run(self, game):
        game.score = 0
        game.iteration = 0
        game.difficulty = 10

        self.surface.fill(util.colour_cyan)

        # Calculate sprite positions, allowing the game to be played at any height and width.
        self.player_y = self.height - 70
        self.bar_hit_y = self.height - 75
        self.sprite_dirt = util.render_rect(
            self, dropper_locale.ID_DIRT, util.colour_brown,
            (0, (self.height - 35), self.width, 35))
        self.sprite_grass = util.render_rect(
            self, dropper_locale.ID_GRASS, util.colour_green,
            (0, (self.height - 45), self.width, 10))
        self.sprite_player = util.render_rect(
            self, dropper_locale.ID_PLAYER, util.colour_black,
            ((self.width / 2), self.player_y, 40, 25))
        self.sprite_score = util.render_text(self,
                                             dropper_locale.GAME_SCORE.format(
                                                 game.score), (70, 20),
                                             center=False)
Esempio n. 4
0
    def run(self, menu_choice=0):
        done = False

        #Static menu part

        menu_items = ["Quit", 
                      "Sound: " + bool_to_str(variables["sound"]), 
                      "Dialogue: " + bool_to_str(variables["dialogue"]), 
                      "Fullscreen mode: " + bool_to_str(variables["fullscreen"]), 
                      'Choose character: %s' % CHARACTERS[variables['character']][0], 
                      "Choose world: " + str(self.world.number)
                                    ]

        #Adds levels to the menu

        count = 0

        while (count <= variables["unlocked" + self.world.name] and count < self.world.level_count):
            menu_items.append("Play level " + str(count + 1))
            count += 1

        #Hi score and best time text on the bgscreen

        if self.score != None:
            score_text = "Your final score: %s" % str(self.score)
            if self.levels == self.world.level_count:
                time_text = "Your final time: %s frames" % str(self.time)
            else:
                time_text = "Didn't pass all levels"

            if self.score > variables["hiscore" + self.world.name]:
                score_text += " - NEW HIGH SCORE!"
                variables["hiscore" + self.world.name] = self.score
            else:
                score_text += " - High score: %s" % variables["hiscore" + self.world.name]

            if (self.time < variables["besttime" + self.world.name] or variables["besttime" + self.world.name] == 0) and (self.levels == self.world.level_count):
                time_text += " - NEW BEST TIME!"
                variables["besttime" + self.world.name] = self.time
            elif variables["besttime" + self.world.name] == 0:
                time_text += " - Best time: no best time"
            else:
                time_text += " - Best time: %s frames" % variables["besttime" + self.world.name]
        else:
            score_text = "High score: %s" % variables["hiscore" + self.world.name]
            if variables["besttime" + self.world.name] == 0:
                time_text = "Best time: no best time"
            else:
                time_text = "Best time: %s frames" % variables["besttime" + self.world.name]


        menu_image = render_text("World " + str(self.world.number) + ": " + self.world.name, COLOR_GUI)
        rect = menu_image.get_rect()
        rect.centerx = SCREEN_WIDTH / 2
        rect.top = GUI_MENU_TOP - 75
        self.bgscreen.blit(menu_image, rect)

        menu_image = render_text(score_text, COLOR_GUI)
        rect = menu_image.get_rect()
        rect.centerx = SCREEN_WIDTH / 2
        rect.top = GUI_MENU_TOP - 50
        self.bgscreen.blit(menu_image, rect)

        menu_image = render_text(time_text, COLOR_GUI)
        rect = menu_image.get_rect()
        rect.centerx = SCREEN_WIDTH / 2
        rect.top = GUI_MENU_TOP - 30
        self.bgscreen.blit(menu_image, rect)
        
        #Uses the menu class for the actual selection functionality

        menu = Menu(self.screen, menu_items, self.bgscreen, "Which way is up?")

        menu_choice = menu.run(menu_choice + MENU_OFFSET)

        #Quit (-3) gets special treatment, because it's returned as a constant when the player presses ESC
        #If offset would be applied to it, it would turn up -6

        if not (menu_choice == MENU_QUIT):
            menu_choice = menu_choice - MENU_OFFSET

        return menu_choice
Esempio n. 5
0
def parse_byline(candidate,all,headline_node):
    authors = []
    score = 0.0
    txt = util.render_text(candidate)
    txt = u' '.join(txt.split()).strip()
    if len(txt) > 200:
        return (authors,score)

    logging.debug("byline: consider <%s> '%s'"%(candidate.tag,txt[:75]))

#    if candidate.tag == 'a':
#        score += eval_author_link(candidate)

    # split up using html structure
    parts = util.iter_text(candidate)

    # pass 1: check for and strip out parts with dates & times
    # TODO: this is a bit ruthless - could lose names if in same block
    parts2 = []
    for txt,el in parts:
        is_pubdate_frag = False
        if pats.pubdate['pubdate_indicator'].search(txt):
            is_pubdate_frag = True

        t,dspan = fuzzydate.parse_date(txt)
        if dspan is not None:
            logging.debug("  +0.1 contains date")
            score += 0.1
            is_pubdate_frag = True

        d,tspan = fuzzydate.parse_time(txt)
        if tspan is not None:
            logging.debug("  +0.1 contains time")
            score += 0.1
            is_pubdate_frag = True

        if not is_pubdate_frag:
            parts2.append((txt,el))

    # pass 2: split up text on likely separators - "and" "in" or any non alphabetic chars...
    # (capturing patterns are included in results)
    split_pat = re.compile(r'((?:\b(?:and|with|in)\b)|(?:[^-_.\w\s]+))',re.IGNORECASE|re.UNICODE)
    parts3 = []
    for txt,el in parts2:
        fragments = split_pat.split(txt)
        for frag in fragments:
            parts3.append((frag.strip(),el))

    # pass three - split out indicatives ("by", "posted by" etc)
    parts4 = []
    for txt,el in parts3:
        for frag in pats.byline['indicative'].split(txt):
            parts4.append((frag,el))

    # clean up
    parts4 = [(txt.strip(),el) for txt,el in parts4]
    parts4 = [(txt,el) for txt,el in parts4 if txt!=u'']

    # now run through classifying and collecting authors
    authors,score = parse_byline_parts(parts4)

    # TEST: likely-looking class or id
    if pats.byline['classes'].search(candidate.get('class','')):
        logging.debug("  +1 likely class")
        score += 1.0
    if pats.byline['classes'].search(candidate.get('id','')):
        logging.debug("  +1 likely id")
        score += 1.0

    # TEST: directly after headline?
    foo = intervening(headline_node,candidate,all)
    if foo is not None:
        if len(foo) == 0:
            logging.debug("  +0.5 directly after headline")
            score += 0.5

    logging.debug( "  total: %.3f" % (score,))

    return (authors, score)
Esempio n. 6
0
    def render_hud(self, window):
        """Renders a Head-Up display on the active window."""
        center      = (75, s.DIMENSIONS[1] - 80)
        speedo_rect = (35, s.DIMENSIONS[1] - 120, 80, 80)
        orbit_pos   = (self.speed / (self.settings["top_speed"] / 4.7)) + 2.35
        start       = self.__circular_orbit(center, -10, orbit_pos)
        finish      = self.__circular_orbit(center, 36, orbit_pos)
        speed       = round((self.speed / s.SEGMENT_HEIGHT) * 1.5, 1)
        font        = pygame.font.Font(s.FONTS["retro_computer"], 16)
        st          = self.special_text
        time_colour = s.COLOURS["text"] if self.time_left > 5 else s.COLOURS["red"]

        pygame.draw.circle(window, s.COLOURS["black"], center, 50, 2)
        pygame.draw.circle(window, s.COLOURS["black"], center, 4)
        pygame.draw.line(window, s.COLOURS["black"], start, finish, 3)
        pygame.draw.arc(window, s.COLOURS["black"], speedo_rect, 0.2, math.pi * 1.25, 5)
        pygame.draw.arc(window, s.COLOURS["red"], speedo_rect, -0.73, 0.2, 5)

        u.render_text("kmph", window, font, s.COLOURS["text"], (110, s.DIMENSIONS[1] - 24))
        u.render_text(str(speed), window, font, s.COLOURS["text"], (10, s.DIMENSIONS[1] - 24))
        u.render_text("Lap", window, font, s.COLOURS["text"], (s.DIMENSIONS[0] - 130, 10))
        u.render_text("%s/%s" % (self.lap, self.total_laps) , window, font, s.COLOURS["text"], (s.DIMENSIONS[0] - 58, 10))

        u.render_text("Time", window, font, time_colour, (10, 10))
        u.render_text(str(math.trunc(self.time_left)), window, font, time_colour, (90, 10))

        # Render special text.
        if st:
            td = (datetime.datetime.now() - st[0])

            if td.seconds > st[1]:
                self.special_text = None
            else:
                bonus_colour = "bonus_a" if (td.microseconds / 25000.0) % 10 > 5 else "bonus_b"
                u.render_text(st[2], window, font, s.COLOURS[bonus_colour], (10, 36))

        # Points rendering needs more care because it grows so fast.
        p_val_text  = font.render(str(math.trunc(self.points)), 1, s.COLOURS["text"])
        p_name_text = font.render("Points", 1, s.COLOURS["text"])
        p_val_x     = s.DIMENSIONS[0] - p_val_text.get_width() - 10

        window.blit(p_val_text, (p_val_x, s.DIMENSIONS[1] - 24))
        window.blit(p_name_text, (p_val_x - 112, s.DIMENSIONS[1] - 24))

        # Hit a point milestone.
        if self.points > self.next_milestone and self.status == self.ALIVE:
            milestone_sfx = pygame.mixer.Sound(os.path.join("lib", "excellent.ogg"))
            milestone_sfx.play()

            self.next_milestone += s.POINT_MILESTONE

            self.__set_special_text("Nice driving!", 2)

        # On the leaderboard!
        if self.high_score > 0 and self.points > self.high_score:
            high_score_sfx = pygame.mixer.Sound(os.path.join("lib", "excellent.ogg"))
            high_score_sfx.play()

            self.high_score = 0

            self.__set_special_text("New High Score!", 2)

        if self.status == self.GAME_OVER:
            self.__game_over_overlay(window)
        elif self.status == self.LEVEL_OVER:
            self.__level_over_overlay(window)

        # Display lap difference (unless we've only done one lap).
        if self.lap_margin != 0 and self.lap > 2 and self.lap_percent < 20:
            diff = self.lap_margin

            if diff <= 0:
                colour = "red"
                sign   = "+"
            else:
                colour = "green"
                sign   = "-"

            u.render_text(sign + str(round(abs(diff), 1)), window, font, s.COLOURS[colour], (10, 40))
Esempio n. 7
0
  def run(self, menu_choice = 0):
    done = False

    clock = pygame.time.Clock()

    menu_items = ["Quit", "Sound: " + bool_to_str(Variables.vdict["sound"]), "Dialogue: " + bool_to_str(Variables.vdict["dialogue"]) ]

    count = 0

    while (count <= Variables.vdict["unlocked"] and count < TOTAL_LEVELS):
      menu_items.append("Level " + str(count + 1))
      count += 1
      
    if self.score != None:
      menu_image = render_text("Your final score: " + str(self.score), COLOR_GUI)
      rect = menu_image.get_rect()
      rect.centerx = SCREEN_WIDTH / 2
      rect.top = GUI_MENU_TOP - 25
      self.screen.blit(menu_image, rect)

    while not done:

      # Pygame event and keyboard input processing
      for event in pygame.event.get():
        if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
          menu_choice = MENU_QUIT
          done = True
        elif (event.type == KEYDOWN and event.key == K_DOWN) or (event.type == JOYAXISMOTION and event.axis == 1 and event.value > 0.7):
          if menu_choice + 4 < len(menu_items):
            menu_choice += 1
            play_sound("click")
        elif (event.type == KEYDOWN and event.key == K_UP) or (event.type == JOYAXISMOTION and event.axis == 1 and event.value < -0.7):
          if menu_choice + 3 > 0:
            menu_choice -= 1
            play_sound("click")
        elif (event.type == KEYDOWN and (event.key == K_z or event.key == K_SPACE or event.key == K_RETURN)) or (event.type == JOYBUTTONDOWN and (event.button == 0 or event.button == 1)):
          done = True

      #Menu rendering
      
      menu_offset =  -(len(menu_items) - 6) * 10

      menu_bg = pygame.image.load(data.picpath("menu", "bg")).convert_alpha()
      rect = menu_bg.get_rect()
      rect.centerx = SCREEN_WIDTH / 2
      rect.top = GUI_MENU_TOP
      self.screen.blit(menu_bg, rect)

      menu_head = render_text("Which way is up?")
      rect = menu_head.get_rect()
      rect.centerx = SCREEN_WIDTH / 2
      rect.top = GUI_MENU_TOP + 50 + menu_offset
      self.screen.blit(menu_head, rect)

      current_menu_index = -3

      for m in menu_items:
        if (menu_choice == current_menu_index):
          color = COLOR_GUI_HILIGHT
        else:
          color = COLOR_GUI
        menu_image = render_text(m, color)
        rect = menu_image.get_rect()
        rect.centerx = SCREEN_WIDTH / 2
        rect.top = GUI_MENU_TOP + 60 + (current_menu_index + 4) * 20 + menu_offset
        self.screen.blit(menu_image, rect)
        current_menu_index += 1

      #Display, clock

      pygame.display.flip()

      clock.tick(FPS)

    return menu_choice
Esempio n. 8
0
    def render_hud(self, window):
        """Renders a Head-Up display on the active window."""
        center = (75, s.DIMENSIONS[1] - 80)
        speedo_rect = (35, s.DIMENSIONS[1] - 120, 80, 80)
        orbit_pos = (self.speed / (self.settings["top_speed"] / 4.7)) + 2.35
        start = self.__circular_orbit(center, -10, orbit_pos)
        finish = self.__circular_orbit(center, 36, orbit_pos)
        speed = round((self.speed / s.SEGMENT_HEIGHT) * 1.5, 1)
        font = pygame.font.Font(s.FONTS["retro_computer"], 16)
        st = self.special_text
        time_colour = s.COLOURS["text"] if self.time_left > 5 else s.COLOURS[
            "red"]

        pygame.draw.circle(window, s.COLOURS["black"], center, 50, 2)
        pygame.draw.circle(window, s.COLOURS["black"], center, 4)
        pygame.draw.line(window, s.COLOURS["black"], start, finish, 3)
        pygame.draw.arc(window, s.COLOURS["black"], speedo_rect, 0.2,
                        math.pi * 1.25, 5)
        pygame.draw.arc(window, s.COLOURS["red"], speedo_rect, -0.73, 0.2, 5)

        u.render_text("kmph", window, font, s.COLOURS["text"],
                      (110, s.DIMENSIONS[1] - 24))
        u.render_text(str(speed), window, font, s.COLOURS["text"],
                      (10, s.DIMENSIONS[1] - 24))
        u.render_text("Lap", window, font, s.COLOURS["text"],
                      (s.DIMENSIONS[0] - 130, 10))
        u.render_text("%s/%s" % (self.lap, self.total_laps), window, font,
                      s.COLOURS["text"], (s.DIMENSIONS[0] - 58, 10))

        u.render_text("Time", window, font, time_colour, (10, 10))
        u.render_text(str(math.trunc(self.time_left)), window, font,
                      time_colour, (90, 10))

        # Render special text.
        if st:
            td = (datetime.datetime.now() - st[0])

            if td.seconds > st[1]:
                self.special_text = None
            else:
                bonus_colour = "bonus_a" if (td.microseconds /
                                             25000.0) % 10 > 5 else "bonus_b"
                u.render_text(st[2], window, font, s.COLOURS[bonus_colour],
                              (10, 36))

        # Points rendering needs more care because it grows so fast.
        p_val_text = font.render(str(math.trunc(self.points)), 1,
                                 s.COLOURS["text"])
        p_name_text = font.render("Points", 1, s.COLOURS["text"])
        p_val_x = s.DIMENSIONS[0] - p_val_text.get_width() - 10

        window.blit(p_val_text, (p_val_x, s.DIMENSIONS[1] - 24))
        window.blit(p_name_text, (p_val_x - 112, s.DIMENSIONS[1] - 24))

        # Hit a point milestone.
        if self.points > self.next_milestone and self.status == self.ALIVE:
            milestone_sfx = pygame.mixer.Sound(
                os.path.join("lib", "excellent.ogg"))
            milestone_sfx.play()

            self.next_milestone += s.POINT_MILESTONE

            self.__set_special_text("Nice driving!", 2)

        # On the leaderboard!
        if self.high_score > 0 and self.points > self.high_score:
            high_score_sfx = pygame.mixer.Sound(
                os.path.join("lib", "excellent.ogg"))
            high_score_sfx.play()

            self.high_score = 0

            self.__set_special_text("New High Score!", 2)

        if self.status == self.GAME_OVER:
            self.__game_over_overlay(window)
        elif self.status == self.LEVEL_OVER:
            self.__level_over_overlay(window)

        # Display lap difference (unless we've only done one lap).
        if self.lap_margin != 0 and self.lap > 2 and self.lap_percent < 20:
            diff = self.lap_margin

            if diff <= 0:
                colour = "red"
                sign = "+"
            else:
                colour = "green"
                sign = "-"

            u.render_text(sign + str(round(abs(diff), 1)), window, font,
                          s.COLOURS[colour], (10, 40))
Esempio n. 9
0
 def run(self, game):
     util.render_text(self, dropper_locale.MENU_TITLE, (200, 100), 50)
     util.render_text(self, dropper_locale.MENU_PLAY, (200, 200))
     util.render_text(self, dropper_locale.MENU_HOW_TO_PLAY, (200, 250))
     util.render_text(self, dropper_locale.MENU_QUIT, (200, 300))
Esempio n. 10
0
    def show(self, game):
        super().show(game)

        # Update the player's position.
        util.move_rect_from_id(self, dropper_locale.ID_PLAYER,
                               (pygame.mouse.get_pos()[0], self.player_y),
                               util.colour_black, util.colour_cyan)

        # Iterate through each bar.
        for sprite in self.sprites:
            if sprite.identifier == dropper_locale.ID_DROPPING_OBJECT:

                # If either part of the bar collides with the player, display the end game screen.
                if sprite.part1.colliderect(
                        self.sprite_player.rect) or sprite.part2.colliderect(
                            self.sprite_player.rect):
                    util.display_screen(game, game.end_game_screen)
                    return
                # If the bar has reached the bottom, remove it.
                elif sprite.rect.y >= self.bar_hit_y:
                    self.sprites.remove(sprite)
                    pygame.draw.rect(self.surface, util.colour_cyan,
                                     sprite.part1)
                    pygame.draw.rect(self.surface, util.colour_cyan,
                                     sprite.part2)

                    game.score += 1
                # Otherwise, move the bar down by 2.
                else:
                    util.move_bar(self.surface, sprite, 2, util.colour_red,
                                  util.colour_cyan)

        # Increment game iteration.
        game.iteration += 1

        if game.iteration >= 100:
            # Increment the difficulty every time the score reaches a multiple of 5,
            # with a maximum difficulty of 3.
            if game.score != 0 and game.score % 5 == 0 and game.difficulty > 3:
                game.difficulty -= 1

            # Reset the iteration and calculate the gap size.
            game.iteration = 0
            gap = (100 - (game.score * 4))

            # Check that the player can actually fit in the gap.
            if gap < 5:
                gap = 5

            # Render the bar.
            util.render_bar(self,
                            dropper_locale.ID_DROPPING_OBJECT, util.colour_red,
                            randint(0, (self.width - 100)), gap)

        # Re-render the score in the top left.
        pygame.draw.rect(self.surface, util.colour_cyan,
                         self.sprite_score.rect)
        self.sprite_score = util.render_text(self,
                                             dropper_locale.GAME_SCORE.format(
                                                 game.score), (70, 20),
                                             center=False)
Esempio n. 11
0
def parse_byline(candidate, all, headline_node):
    authors = []
    score = 0.0
    txt = util.render_text(candidate)
    txt = u' '.join(txt.split()).strip()
    if len(txt) > 200:
        return (authors, score)

    logging.debug("byline: consider <%s> '%s'" % (candidate.tag, txt[:75]))

    #    if candidate.tag == 'a':
    #        score += eval_author_link(candidate)

    # split up using html structure
    parts = util.iter_text(candidate)

    # pass 1: check for and strip out parts with dates & times
    # TODO: this is a bit ruthless - could lose names if in same block
    parts2 = []
    for txt, el in parts:
        is_pubdate_frag = False
        if pats.pubdate['pubdate_indicator'].search(txt):
            is_pubdate_frag = True

        t, dspan = fuzzydate.parse_date(txt)
        if dspan is not None:
            logging.debug("  +0.1 contains date")
            score += 0.1
            is_pubdate_frag = True

        d, tspan = fuzzydate.parse_time(txt)
        if tspan is not None:
            logging.debug("  +0.1 contains time")
            score += 0.1
            is_pubdate_frag = True

        if not is_pubdate_frag:
            parts2.append((txt, el))

    # pass 2: split up text on likely separators - "and" "in" or any non alphabetic chars...
    # (capturing patterns are included in results)
    split_pat = re.compile(r'((?:\b(?:and|with|in)\b)|(?:[^-_.\w\s]+))',
                           re.IGNORECASE | re.UNICODE)
    parts3 = []
    for txt, el in parts2:
        fragments = split_pat.split(txt)
        for frag in fragments:
            parts3.append((frag.strip(), el))

    # pass three - split out indicatives ("by", "posted by" etc)
    parts4 = []
    for txt, el in parts3:
        for frag in pats.byline['indicative'].split(txt):
            parts4.append((frag, el))

    # clean up
    parts4 = [(txt.strip(), el) for txt, el in parts4]
    parts4 = [(txt, el) for txt, el in parts4 if txt != u'']

    # now run through classifying and collecting authors
    authors, score = parse_byline_parts(parts4)

    # TEST: likely-looking class or id
    if pats.byline['classes'].search(candidate.get('class', '')):
        logging.debug("  +1 likely class")
        score += 1.0
    if pats.byline['classes'].search(candidate.get('id', '')):
        logging.debug("  +1 likely id")
        score += 1.0

    # TEST: directly after headline?
    foo = intervening(headline_node, candidate, all)
    if foo is not None:
        if len(foo) == 0:
            logging.debug("  +0.5 directly after headline")
            score += 0.5

    logging.debug("  total: %.3f" % (score, ))

    return (authors, score)
Esempio n. 12
0
  def run(self, menu_choice = 0):
    done = False

    clock = pygame.time.Clock()

    self.screen.blit(self.bgscreen, (0, 0))      #Renders the menu background, usually the faded out game display
                                                 #Or a black screen
    #Menu loop

    while not done:

      # Pygame event and keyboard input processing
      for event in pygame.event.get():
        if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
          menu_choice = MENU_QUIT
          done = True
        elif (event.type == KEYDOWN and event.key == K_DOWN) or (event.type == JOYAXISMOTION and event.axis == 1 and event.value > 0.7):
          if menu_choice + 1 < len(self.menu_items):
            menu_choice += 1
            play_sound("click")
        elif (event.type == KEYDOWN and event.key == K_UP) or (event.type == JOYAXISMOTION and event.axis == 1 and event.value < -0.7):
          if menu_choice > 0:
            menu_choice -= 1
            play_sound("click")
        elif (event.type == KEYDOWN and (event.key == K_z or event.key == K_SPACE or event.key == K_RETURN)) or (event.type == JOYBUTTONDOWN and (event.button == 0 or event.button == 1)):
          done = True

      #Menu rendering

      #Menu offset value centers the menu when the maximum amount of choices is not visible

      if len(self.menu_items) < MENU_MAX_VISIBLE:
        menu_offset = -(len(self.menu_items) - 5) * 10
      else:
        menu_offset = -(MENU_MAX_VISIBLE - 5) * 10

      menu_bg = pygame.image.load(data.picpath("menu", "bg")).convert_alpha()
      rect = menu_bg.get_rect()
      rect.centerx = SCREEN_WIDTH / 2
      rect.top = GUI_MENU_TOP
      self.screen.blit(menu_bg, rect)

      if self.heading_text != None:
        menu_head = render_text(self.heading_text)
        rect = menu_head.get_rect()
        rect.centerx = SCREEN_WIDTH / 2
        rect.top = GUI_MENU_TOP + 50 + menu_offset
        self.screen.blit(menu_head, rect)

      #If the menu choice is greater than the second last menu item on screen,
      #the menu must be scrolled:
      if menu_choice > (MENU_MAX_VISIBLE - 1):
        current_menu_index = menu_choice - MENU_MAX_VISIBLE
        if (menu_choice + 1) < len(self.menu_items):
          current_menu_index += 1
      else:
        current_menu_index = 0

      menu_visible = 0

      while (not (menu_visible > MENU_MAX_VISIBLE or (current_menu_index) == len(self.menu_items))):
        m = self.menu_items[current_menu_index]
        if (menu_choice == current_menu_index):
          menu_image = render_text(m, COLOR_GUI_HILIGHT, COLOR_GUI_DARK)
        else:
          menu_image = render_text(m, COLOR_GUI)
        rect = menu_image.get_rect()
        rect.centerx = SCREEN_WIDTH / 2
        rect.top = GUI_MENU_TOP + 60 + (menu_visible + 1) * 20 + menu_offset
        self.screen.blit(menu_image, rect)
        current_menu_index += 1
        menu_visible += 1

      #Display, clock

      pygame.display.flip()

      clock.tick(FPS)

    return menu_choice