Exemplo n.º 1
0
    def init(self):
        self.xp_label = LabelComp(self.x,
                                  self.y,
                                  self.width,
                                  self.height,
                                  f'XP: {GameData.user.data["xp"]}',
                                  color=(255, 255, 255))
        self.add_component(self.xp_label)

        self.level_label = LabelComp(self.x,
                                     self.y + GameData.tile_size,
                                     self.width,
                                     self.height,
                                     f'Level: {GameData.user.data["level"]}',
                                     color=(255, 255, 255))
        self.add_component(self.level_label)
Exemplo n.º 2
0
    def init(self):
        new_label = LabelComp(self.x, self.y, self.width, self.height,
                              self.text, 40)
        self.add_component(new_label)

        timer = Timer(self.free)
        self.add_component(timer)
        timer.start(self.duration)
Exemplo n.º 3
0
    def init(self):
        user_data = GameData.user.data
        y_start = 20
        size = (400, 200)

        username_label = LabelComp(self.x + self.width / 2 - size[0] / 2,
                                   self.y + y_start, size[0], 50,
                                   f'{user_data["username"]}', 44)
        self.add_component(username_label)

        # levels completed label
        text = "Levels completed:\n"
        for level_name in user_data["completed_levels"]:
            text += f'{level_name}\n'
        if len(user_data["completed_levels"]) == 0:
            text += "No levels completed"

        levels_label = LabelComp(self.x + self.width / 2 - size[0] / 2,
                                 username_label.bottom + y_start, size[0],
                                 size[1] * 1.5, text, 32)
        self.add_component(levels_label)

        coins_label = LabelComp(self.x + self.width / 2 - size[0] / 2,
                                levels_label.bottom, size[0], size[1] / 4,
                                f'Coins collected: {user_data["coins"]}', 32)
        self.add_component(coins_label)

        level_label = LabelComp(self.x + self.width / 2 - size[0] / 2,
                                coins_label.bottom + y_start, size[0],
                                size[1] / 4, f'Level: {user_data["level"]}',
                                32)
        self.add_component(level_label)

        # back button
        size = (400, 70)
        back_button = ButtonComp(self.x + self.width / 2 - size[0] / 2,
                                 self.y + self.height - size[1] - y_start,
                                 size[0],
                                 size[1],
                                 "Back",
                                 40,
                                 pygame.Color("dodgerblue"),
                                 callback=self.load_menu,
                                 color=(255, 255, 255))
        self.add_component(back_button)
Exemplo n.º 4
0
    def init(self):
        size = (200, 100)
        start_y = 50
        new_label = LabelComp(self.x + self.width / 2 - size[0] / 2,
                              self.y + start_y, size[0], size[1] * 2,
                              "Good job!\nYou completed the level!", 45)
        self.add_component(new_label)

        menu_button = ButtonComp(self.x + self.width / 2 - size[0] / 2,
                                 self.y + start_y + 300, size[0],
                                 size[1], "Main Menu", 40,
                                 pygame.Color("dodgerblue"), (0, 0, 0), None,
                                 self.load_main_menu)
        self.add_component(menu_button)
Exemplo n.º 5
0
    def init(self):
        size = (200, 100)
        start_y = 50
        new_label = LabelComp(self.x + self.width / 2 - size[0] / 2,
                              self.y + start_y, size[0], size[1] * 2,
                              "Press ESCAPE to\nunpause the game", 45)
        self.add_component(new_label)

        menu_button = ButtonComp(self.x + self.width / 2 - size[0] / 2,
                                 self.y + start_y + 300, size[0],
                                 size[1], "Main Menu", 40,
                                 pygame.Color("dodgerblue"), (0, 0, 0), None,
                                 self.load_main_menu)
        self.add_component(menu_button)
Exemplo n.º 6
0
    def init(self):
        size = (300, 100)
        start_y = 50
        new_label = LabelComp(self.x + self.width / 2 - size[0] / 2,
                              self.y + start_y, size[0], size[1] * 2,
                              "Main Menu", 50)
        self.add_component(new_label)

        play_button = ButtonComp(
            self.x + self.width / 2 - size[0] / 2,
            self.y + start_y + 300,
            size[0],
            size[1],
            "Play",
            40,
            pygame.Color("dodgerblue"),
            (255, 255, 255),
            None,
            self.load_levels_selector,
        )
        self.add_component(play_button)

        stats_button = play_button = ButtonComp(
            self.x + self.width / 2 - size[0] / 2,
            self.y + start_y + 420,
            size[0],
            size[1],
            "Stats",
            40,
            pygame.Color("dodgerblue"),
            (255, 255, 255),
            None,
            self.load_user_stats,
        )
        self.add_component(stats_button)

        quit_button = ButtonComp(
            self.x + self.width / 2 - size[0] / 2,
            self.y + start_y + 540,
            size[0],
            size[1],
            "Quit to login",
            40,
            pygame.Color("dodgerblue"),
            (255, 255, 255),
            None,
            self.quit_to_login,
        )
        self.add_component(quit_button)
Exemplo n.º 7
0
 def init(self):
     # create coin sprite
     coins_sprite = Sprite('coins',
                           GameData.tile_size,
                           GameData.tile_size,
                           self.x,
                           self.y,
                           ui_sprite=True)
     coins_label = LabelComp(self.x + GameData.tile_size,
                             self.y,
                             GameData.tile_size,
                             GameData.tile_size,
                             '0',
                             40,
                             color=(255, 255, 255))
     self.add_component(coins_sprite)
     self.add_component(coins_label)
Exemplo n.º 8
0
    def init(self):
        self.label_comp = LabelComp(self.x, self.y, self.width, self.height, "FPS: ", 32, center = False)

        self.add_component(self.label_comp)