Example #1
0
    def __init__(self, screensize, gametype, title_prefix):
        self.name = "highscore"
        self.hasclicked = False
        self.width = screensize[0]
        self.background = pygame.Surface(screensize).convert()
        self.background.fill(HIGHSCORE['bgcolor'])
        self.changed = True
        highscores = get_highscores(HIGHSCORE['show-n-scores'],
                                    gametype=gametype)

        title = Textbox(name="highscore_title",
                        size=HIGHSCORE['title-size'],
                        location=(0, 0),
                        text_color=HIGHSCORE['title-text-color'],
                        surface_color=HIGHSCORE['title-bgcolor'],
                        text_size=HIGHSCORE['title-text-size'],
                        bold=HIGHSCORE['title-bold'])
        title.update(title_prefix + HIGHSCORE['title-text'])

        score_boxes = []
        placement = 0

        for i in highscores:
            placement += 1
            highscore = Textbox(name="highscore_title",
                                size=HIGHSCORE['score-size'],
                                location=(0, 0),
                                text_color=HIGHSCORE['score-text-color'],
                                surface_color=HIGHSCORE['score-bgcolor'],
                                text_size=HIGHSCORE['score-text-size'],
                                bold=HIGHSCORE['score-bold'],
                                font=HIGHSCORE['score-font'])
            highscore.update('{0:<2}'.format(str(placement)) +
                             HIGHSCORE['score-separator'] +
                             '{0:>15}'.format(str(i)))

            self.background.blit(
                highscore.surface,
                highscore.surface.get_rect(centery=75 + 40 * placement,
                                           centerx=self.width / 2))

        self.background.blit(
            title.surface,
            title.surface.get_rect(centery=50, centerx=self.width / 2))
Example #2
0
    def __init__(self, screensize):
        self.button_info.reverse()

        self.background_color = MENU['bgcolor']
        self.background = pygame.Surface(screensize).convert()
        self.background.fill(self.background_color)
        self.width, self.height = screensize
        self.changed = True

        self.button_amount = len(self.button_info)

        self.main_text = Textbox(name="main_text",
                                 size=MENU['title-size'],
                                 location=(0, 0),
                                 text_color=MENU['title-color'],
                                 surface_color=MENU['title-bgcolor'],
                                 text_size=MENU['title-text-size'])

        self.main_text.update(self.title)

        button_height = (
            (self.height - MENU['title-size'][1]) / self.button_amount -
            MENU['button-padding'])
        button_size = (self.width - (MENU['button-padding'] * 2),
                       button_height)

        calc_button_top = lambda n: (self.height - button_height * n - MENU[
            'button-padding'] * (n - 1) - MENU['button-padding'])

        self.buttons = []
        for n, button in enumerate(self.button_info):
            new_button = Button(name=button['name'],
                                size=button_size,
                                text=button['text'],
                                location=(0, 0))

            new_button.rect = new_button.surface.get_rect(
                top=calc_button_top(n + 1), centerx=self.width / 2)

            self.buttons.append(new_button)

        self.background.blit(
            self.main_text.surface,
            self.main_text.surface.get_rect(centery=MENU['title-center-y'],
                                            centerx=self.width / 2))

        self.buttonevents = []