예제 #1
0
    def __init__(self, display):
        self.display = display
        self.state = "menu"
        self.game_reference = None

        # Background Setup
        self.background = pygame_gui.Image(paths.uiMenuPath + "background.png", 0, 0)

        # Title / Header setup
        self.title = pygame_gui.Text(
            constants.DISPLAY_NAME,
            50, constants.FONTS["colour"], constants.FONTS["main"],
            250, 150)

        # Making panel around text, with padding.
        title_rect = pygame.Rect(self.title.get_rect())
        title_padding = 5
        title_rect.x -= title_padding
        title_rect.width += title_padding*2
        self.title_panel = pygame_gui.Panel(title_rect, 150, constants.COLOURS["panel"])

        self.title_logo = pygame.image.load(paths.uiMenuPath + "logo-big.png")
        self.logo_panel = pygame_gui.Panel([title_rect.right, title_rect.y, title_rect.height, title_rect.height],
                                           150, (0, 0, 0))

        # Menu location (New, Load and Leaderboard)
        self.menux = 425
        self.menuy = 370

        # GUI Menu Setup
        self.newgame_button = pygame_gui.TextButton(
            [self.menux, self.menuy, 150, 40],
            220, 200,
            "new game",
            constants.FONTS["sizes"]["large"], constants.FONTS["colour"], constants.FONTS["main"])

        self.continue_button = pygame_gui.TextButton(
            [self.menux, self.menuy + 40, 150, 40],
            220, 200,
            "continue",
            constants.FONTS["sizes"]["large"], constants.FONTS["colour"], constants.FONTS["main"])

        self.leaderboard_button = pygame_gui.TextButton(
            [self.menux, self.menuy + 80, 150, 40],
            220, 200,
            "leaderboard",
            constants.FONTS["sizes"]["large"], constants.FONTS["colour"], constants.FONTS["main"])

        self.about_button = pygame_gui.TextButton(
            [5, self.display.get_height() - 45, 80, 40],
            220, 200,
            "about",
            constants.FONTS["sizes"]["large"], constants.FONTS["colour"], constants.FONTS["main"])

        self.show_about = False
        self.about = About(self)

        self.run()
예제 #2
0
    def __init__(self, display):
        self.display = display
        self.state = "load_game"
        self.game_reference = None

        # Background Setup
        self.background = pygame_gui.Image(paths.uiMenuPath + "background.png",
                                           0, 0)
        self.back_panel = pygame_gui.Panel([100, 100, 800, 500], 150,
                                           constants.COLOURS["panel"])

        # GUI Setup
        self.back_button = pygame_gui.Button(
            paths.uiPath + "backwhite.png",
            paths.uiPath + "backwhite-hover.png", 5, 5)
        self.title = pygame_gui.Text("Select Game: ",
                                     constants.FONTS["sizes"]["large"],
                                     constants.FONTS["colour"],
                                     constants.FONTS["main"], 110, 110)

        self.file_selector = FileSelector(self, [250, 150])
        self.try_delete = None  # if True, displays delete_message, try's to delete file in to_delete if ok pressed
        self.to_delete = None
        self.delete_message = GUI.CheckMessage(self, "Are You Sure?", [
            "The game will be permanently deleted,", "and can't be recovered!"
        ])

        self.page_back_button = pygame_gui.Button(
            paths.uiPath + "pageback.png", paths.uiPath + "pageback-hover.png",
            820, 550)
        self.page_forward_button = pygame_gui.Button(
            paths.uiPath + "pageforward.png",
            paths.uiPath + "pageforward-hover.png", 860, 550)

        self.run()
예제 #3
0
    def __init__(self, control, game_name, position):
        self.control = control  # Control in this case is the LoadGame object.
        self.game_name = game_name
        self.position = position

        # GUI Setup
        self.back_panel = pygame_gui.Panel(
            [self.position[0], self.position[1], 450, 50], 255,
            constants.COLOURS["panel"])
        self.back_panel_hover = pygame_gui.Panel(
            [self.position[0], self.position[1], 450, 50], 255,
            constants.COLOURS["panel-hover"])

        self.text = pygame_gui.Text(game_name,
                                    constants.FONTS["sizes"]["medium"],
                                    constants.FONTS["colour"],
                                    constants.FONTS["main"],
                                    self.position[0] + 50,
                                    self.position[1] + 15)
예제 #4
0
파일: menu.py 프로젝트: wushiwang/Escape
    def __init__(self, display):
        self.display = display
        self.state = "menu"

        # Background Setup
        self.background = pygame_gui.Image(
            paths.imagePath + "background-menu.png", 0, 0)

        # Title / Header setup
        self.title = pygame_gui.Text(constants.DISPLAY_NAME, 45,
                                     constants.FONTS["colour"],
                                     constants.FONTS["main"], 430, 180)

        # Making panel around text, with padding.
        title_rect = pygame.Rect(self.title.get_rect())
        title_padding = 5
        title_rect.x -= title_padding
        title_rect.width += title_padding * 2
        self.title_panel = pygame_gui.Panel(title_rect, 150,
                                            constants.COLOURS["panel"])

        # Menu location (New, Load and Leaderboard)
        self.menux = 420
        self.menuy = 300

        # GUI Menu Setup
        self.continue_button = pygame_gui.TextButton(
            [self.menux, self.menuy + 40, 150, 40], constants.COLOURS["panel"],
            constants.COLOURS["panel-hover"], "select level",
            constants.FONTS["sizes"]["large"], constants.FONTS["colour"],
            constants.FONTS["main"])

        self.editor_button = pygame_gui.TextButton(
            [self.menux, self.menuy + 90, 150, 40], constants.COLOURS["panel"],
            constants.COLOURS["panel-hover"], "editor",
            constants.FONTS["sizes"]["large"], constants.FONTS["colour"],
            constants.FONTS["main"])

        self.version = pygame_gui.Text(constants.version,
                                       constants.FONTS["sizes"]["medium"],
                                       constants.FONTS["colour"],
                                       constants.FONTS["main"], 3,
                                       constants.DISPLAY_SIZE[1] - 20)

        self.project_github = WebLink("GitHub Page",
                                      "https://github.com/Ben-Ryder/Escape",
                                      470, constants.DISPLAY_SIZE[1] - 20)

        self.personal_site = WebLink("By Ben Ryder",
                                     "https://github.com/Ben-Ryder",
                                     constants.DISPLAY_SIZE[0] - 87,
                                     constants.DISPLAY_SIZE[1] - 20)

        self.run()
예제 #5
0
    def __init__(self, display):
        self.display = display
        self.state = "leaderboard"

        # Background Setup
        self.background = pygame_gui.Image(paths.uiMenuPath + "background.png",
                                           0, 0)
        self.back_panel = pygame_gui.Panel([100, 100, 800, 500], 150,
                                           constants.COLOURS["panel"])

        # GUI Setup
        self.back = pygame_gui.Button(paths.uiPath + "backwhite.png",
                                      paths.uiPath + "backwhite-hover.png", 5,
                                      5)
        self.title = pygame_gui.Text("Leaderboard: ",
                                     constants.FONTS["sizes"]["large"],
                                     constants.FONTS["colour"],
                                     constants.FONTS["main"], 110, 110)

        self.top_ten = pygame_gui.Text("(top 10)",
                                       constants.FONTS["sizes"]["large"],
                                       constants.FONTS["colour"],
                                       constants.FONTS["main"], 825, 110)

        self.rank_text = pygame_gui.Text("rank",
                                         constants.FONTS["sizes"]["medium"],
                                         constants.FONTS["colour"],
                                         constants.FONTS["main"], 310, 150)

        self.name_text = pygame_gui.Text("name",
                                         constants.FONTS["sizes"]["medium"],
                                         constants.FONTS["colour"],
                                         constants.FONTS["main"], 380, 150)

        self.score_text = pygame_gui.Text("score",
                                          constants.FONTS["sizes"]["medium"],
                                          constants.FONTS["colour"],
                                          constants.FONTS["main"], 605, 150)

        self.leaderboard_reader = LeaderboardEditor()
        self.slots = []
        x, y = [300, 170]
        padding = 40  # between player slots
        rank = 1
        for player in self.leaderboard_reader.get_high_scores(10):
            self.slots.append(LeaderboardSlot(player[0], player[1], rank, x,
                                              y))
            y += padding
            rank += 1

        self.run()
예제 #6
0
    def __init__(self, GUI):
        self.GUI = GUI

        size = [350, 200]
        self.rect = [constants.DISPLAY_SIZE[0] / 2 - size[0] / 2,  # center of screen
                     constants.DISPLAY_SIZE[1] / 2 - size[1] / 2,
                     size[0],
                     size[1]]

        self.background = pygame_gui.Panel([self.rect[0], self.rect[1], self.rect[2], self.rect[3]], 230, (0, 0, 0))

        self.title = pygame_gui.Text(
            "About",
            constants.FONTS["sizes"]["medium"], constants.FONTS["colour"], constants.FONTS["main"],
            self.rect[0] + 5, self.rect[1] + 5)

        self.project_title = pygame_gui.Text(
            "Project Home:",
            constants.FONTS["sizes"]["medium"], constants.FONTS["colour"], constants.FONTS["main"],
            self.rect[0] + 5, self.rect[1] + 40)

        self.project_github = WebLink("https://github.com/Ben-Ryder/Conqueror-of-Empires",
                                      "https://github.com/Ben-Ryder/Conqueror-of-Empires",
                                      self.rect[0] + 5, self.rect[1] + 60)

        self.project_message = pygame_gui.Text(
            "(feel free to suggest improvements, rasie issues etc)",
            constants.FONTS["sizes"]["small"], (200, 200, 200), constants.FONTS["main"],
            self.rect[0] + 5, self.rect[1] + 77)

        self.personal_title = pygame_gui.Text(
            "Developed by Ben Ryder",
            constants.FONTS["sizes"]["medium"], constants.FONTS["colour"], constants.FONTS["main"],
            self.rect[0] + 5, self.rect[1] + 110)

        self.personal_site = WebLink("https://ben-ryder.github.io",
                                     "https://ben-ryder.github.io",
                                     self.rect[0] + 5, self.rect[1] + 130)

        self.version = pygame_gui.Text(
            constants.version,
            constants.FONTS["sizes"]["medium"], constants.FONTS["colour"], constants.FONTS["main"],
            self.rect[0] + 5, self.rect[1] + self.rect[3] - 20)

        ok_rect = [self.rect[0] + self.rect[2] - 35, self.rect[1] + self.rect[3] - 30, 35, 30]
        self.ok_button = pygame_gui.TextButton(
            ok_rect,
            0, 100,
            "ok",
            constants.FONTS["sizes"]["large"], constants.FONTS["colour"], constants.FONTS["main"])
예제 #7
0
    def __init__(self, control, game_name, position):
        self.control = control  # Control in this case is the LoadGame object.
        self.game_name = game_name
        self.position = position

        # GUI Setup
        self.back_panel = pygame_gui.Panel(
            [self.position[0], self.position[1], 500, 50], 100,
            constants.COLOURS["panel"])
        self.back_panel_hover = pygame_gui.Panel(
            [self.position[0], self.position[1], 500, 50], 50,
            constants.COLOURS["panel"])

        self.text = pygame_gui.Text(game_name,
                                    constants.FONTS["sizes"]["medium"],
                                    constants.FONTS["colour"],
                                    constants.FONTS["main"],
                                    self.position[0] + 50,
                                    self.position[1] + 15)

        self.quit_button = pygame_gui.Button(paths.uiPath + "cross.png",
                                             paths.uiPath + "cross-hover.png",
                                             self.position[0] + 450,
                                             self.position[1] + 8)
예제 #8
0
    def __init__(self, name, score, rank, x, y):
        self.panel = pygame_gui.Panel([x, y, 400, 30], 100, constants.COLOURS["panel"])

        self.rank_text = pygame_gui.Text(
            str(rank),
            constants.FONTS["sizes"]["medium"], constants.FONTS["colour"], constants.FONTS["main"],
            x + 20, y + 5)

        self.name_text = pygame_gui.Text(
            name,
            constants.FONTS["sizes"]["medium"], constants.FONTS["colour"], constants.FONTS["main"],
            x + 80, y + 5)

        self.score_text = pygame_gui.Text(
            "{:,}".format(score),
            constants.FONTS["sizes"]["medium"], constants.FONTS["colour"], constants.FONTS["main"],
            x + 302, y + 5)
예제 #9
0
    def __init__(self, player_manager, origin, colour, name=""):
        self.player_manager = player_manager
        self.origin = origin
        self.colour = colour

        # Background
        self.back_panel = pygame_gui.Panel(
            [self.origin[0], self.origin[1], 500, 50], 100,
            constants.COLOURS["black"])

        self.name_entry = pygame_gui.Entry(
            paths.uiMenuPath + "input-normal.png",
            paths.uiMenuPath + "input-normal-hover.png",
            paths.uiMenuPath + "input-normal-focused.png",
            paths.uiMenuPath + "input-normal-hover-focused.png", name,
            constants.FONTS["sizes"]["medium"], constants.FONTS["colour"],
            constants.FONTS["main"], 10, 5, True, self.origin[0] + 60,
            self.origin[1] + 10)

        self.delete_self = pygame_gui.Button(paths.uiPath + "cross.png",
                                             paths.uiPath + "cross-hover.png",
                                             self.origin[0] + 430,
                                             self.origin[1] + 8)
예제 #10
0
    def __init__(self, display, reason):
        self.display = display

        size = [250, 100]
        self.rect = pygame.Rect(display.get_width() / 2 - size[0] / 2,
                                display.get_height() / 2 - size[1] / 2,
                                size[0], size[1])
        self.background = pygame_gui.Panel(self.rect, 255, (10, 10, 10))

        if reason == "won":
            text = "Level Completed"
        elif reason == "lost":
            text = "Level Failed"
        else:
            raise Exception("Invalid reason for game end")

        self.title = pygame_gui.Text(text, 26, (255, 255, 255),
                                     constants.FONTS["main-bold"], self.rect.x,
                                     self.rect.y + 10)
        self.title.change_position(
            self.rect.centerx - self.title.rect.width / 2, self.title.rect.y)

        sizes = [self.rect.width / 2, self.rect.height / 2]
        self.menu_button = pygame_gui.TextButton(
            [self.rect.x, self.rect.centery, sizes[0], sizes[1]], (10, 10, 10),
            (30, 30, 30), "< menu", constants.FONTS["sizes"]["medium"],
            constants.FONTS["colour"], constants.FONTS["main"])

        self.restart_button = pygame_gui.TextButton(
            [self.rect.centerx, self.rect.centery, sizes[0], sizes[1]],
            (10, 10, 10), (30, 30, 30), "restart >",
            constants.FONTS["sizes"]["medium"], constants.FONTS["colour"],
            constants.FONTS["main"])

        self.option = "game-over"
        self.run()
예제 #11
0
    def __init__(self, display):
        self.display = display
        self.state = "new_game"
        self.game_reference = None

        # Background Setup
        self.background = pygame_gui.Image(paths.uiMenuPath + "background.png",
                                           0, 0)
        self.back_panel = pygame_gui.Panel([100, 100, 800, 500], 150,
                                           constants.COLOURS["panel"])

        # GUI Setup
        self.origin = [150, 30]
        # General
        self.back_button = pygame_gui.Button(
            paths.uiPath + "backwhite.png",
            paths.uiPath + "backwhite-hover.png", 5, 5)

        self.title_text = pygame_gui.Text("Create Game:",
                                          constants.FONTS["sizes"]["large"],
                                          constants.FONTS["colour"],
                                          constants.FONTS["main"], 110, 110)

        self.play_button = pygame_gui.Button(
            paths.uiPath + "forwardwhite.png",
            paths.uiPath + "forwardwhite-hover.png", self.origin[0] + 700,
            self.origin[1] + 525)

        # Game Input Setup
        self.game_name_prompt = pygame_gui.Text(
            "Game Name:", constants.FONTS["sizes"]["medium"],
            constants.FONTS["colour"], constants.FONTS["main"],
            self.origin[0] + 100, self.origin[1] + 150)

        self.game_name_input = pygame_gui.Entry(
            paths.uiMenuPath + "input-large.png",
            paths.uiMenuPath + "input-large-hover.png",
            paths.uiMenuPath + "input-large-focused.png",
            paths.uiMenuPath + "input-large-hover-focused.png", "",
            constants.FONTS["sizes"]["medium"], constants.FONTS["colour"],
            constants.FONTS["main"], 10, 5, True, self.origin[0] + 250,
            self.origin[1] + 145)

        self.game_name_error_text = pygame_gui.Text(
            "", constants.FONTS["sizes"]["small"], constants.COLOURS["red"],
            constants.FONTS["main-bold-italic"], self.origin[0] + 250,
            self.origin[1] + 180)

        # Map Input Setup
        self.map_select_prompt = pygame_gui.Text(
            "Select Map:", constants.FONTS["sizes"]["medium"],
            constants.FONTS["colour"], constants.FONTS["main"],
            self.origin[0] + 100, self.origin[1] + 200)

        self.map_selector = MapSelector(self.origin[0] + 250,
                                        self.origin[1] + 200)

        # Player Input Setup
        self.players_prompt = pygame_gui.Text(
            "Players:", constants.FONTS["sizes"]["medium"],
            constants.FONTS["colour"], constants.FONTS["main"],
            self.origin[0] + 100, self.origin[1] + 250)

        self.player_slots_error = pygame_gui.Text(
            "", constants.FONTS["sizes"]["small"], constants.COLOURS["red"],
            constants.FONTS["main-bold-italic"], self.origin[0] + 200,
            self.origin[1] + 255)

        self.player_manager = PlayerManager(
            4, [self.origin[0] + 100, self.origin[1] + 290])

        self.run()