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()
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()
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"])
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()
def __init__(self, level, display): self.level = level self.left_option = None self.right_option = None self.patrol_focus = None # GUI Setup # Settings Buttons self.menu_button = pygame_gui.TextButton([ display.get_width() - self.level.EDITOR_SIZE, 0, self.level.EDITOR_SIZE, self.level.TILE_SIZE ], (20, 20, 20), (40, 40, 40), "back to menu", 20, (200, 200, 200), constants.FONTS["main"]) self.level_name = pygame_gui.RectEntry([ display.get_width() - self.level.EDITOR_SIZE, self.level.TILE_SIZE, self.level.EDITOR_SIZE, self.level.TILE_SIZE ], 2, (255, 255, 255), (255, 255, 255), (160, 160, 160), (160, 160, 160), (255, 255, 255), (30, 100, 30), (160, 160, 160), (30, 100, 30), "enter level name", 25, (0, 0, 0), constants.FONTS["main"], 10, 5, False) self.save_button = pygame_gui.TextButton([ display.get_width() - self.level.EDITOR_SIZE / 2, self.level.TILE_SIZE * 2, self.level.EDITOR_SIZE / 2, self.level.TILE_SIZE ], (10, 40, 10), (20, 100, 20), "save", 20, (200, 200, 200), constants.FONTS["main"]) self.load_button = pygame_gui.TextButton([ display.get_width() - self.level.EDITOR_SIZE, self.level.TILE_SIZE * 2, self.level.EDITOR_SIZE / 2, self.level.TILE_SIZE ], (40, 40, 40), (60, 60, 60), "load", 20, (200, 200, 200), constants.FONTS["main"]) self.tile_size = pygame_gui.RectEntry( [ display.get_width() - self.level.EDITOR_SIZE, self.level.TILE_SIZE * 3, self.level.TILE_SIZE, self.level.TILE_SIZE ], 2, (255, 255, 255), (220, 220, 220), (160, 160, 160), (140, 140, 140), (255, 255, 255), (30, 100, 30), (160, 160, 160), (30, 100, 30), str(self.level.TILE_SIZE), 25, (0, 0, 0), constants.FONTS["main"], 8, 4, False) self.map_rows = pygame_gui.RectEntry( [ display.get_width() - self.level.EDITOR_SIZE + self.level.TILE_SIZE, self.level.TILE_SIZE * 3, self.level.TILE_SIZE, self.level.TILE_SIZE ], 2, (255, 255, 255), (220, 220, 220), (160, 160, 160), (140, 140, 140), (255, 255, 255), (30, 100, 30), (160, 160, 160), (30, 100, 30), str(self.level.MAP_SIZE[0]), 25, (0, 0, 0), constants.FONTS["main"], 8, 4, False) self.map_columns = pygame_gui.RectEntry( [ display.get_width() - self.level.EDITOR_SIZE + self.level.TILE_SIZE * 2, self.level.TILE_SIZE * 3, self.level.TILE_SIZE, self.level.TILE_SIZE ], 2, (255, 255, 255), (220, 220, 220), (160, 160, 160), (140, 140, 140), (255, 255, 255), (30, 100, 30), (160, 160, 160), (30, 100, 30), str(self.level.MAP_SIZE[1]), 25, (0, 0, 0), constants.FONTS["main"], 8, 4, False) self.new = pygame_gui.TextButton([ display.get_width() - self.level.TILE_SIZE * 3, self.level.TILE_SIZE * 3, self.level.TILE_SIZE * 3, self.level.TILE_SIZE ], (100, 20, 20), (130, 30, 30), "new", 20, (200, 200, 200), constants.FONTS["main"]) # Selector origin = [self.level.DISPLAY_SIZE[0], self.level.TILE_SIZE * 5] padding = self.level.TILE_SIZE / 3 self.path_button = SelectorButton(paths.tilePath + "path.png", paths.tilePath + "path.png", origin[0] + padding, origin[1]) self.path_button.resize(self.level.TILE_SIZE, self.level.TILE_SIZE) self.wall_button = SelectorButton(paths.tilePath + "wall.png", paths.tilePath + "wall.png", origin[0] + padding * 5, origin[1]) self.wall_button.resize(self.level.TILE_SIZE, self.level.TILE_SIZE) self.spawn_button = SelectorButton(paths.tilePath + "spawn-point.png", paths.tilePath + "spawn-point.png", origin[0] + padding * 10, origin[1]) self.spawn_button.resize(self.level.TILE_SIZE, self.level.TILE_SIZE) self.safe_button = SelectorButton(paths.tilePath + "safe-point.png", paths.tilePath + "safe-point.png", origin[0] + padding * 14, origin[1]) self.safe_button.resize(self.level.TILE_SIZE, self.level.TILE_SIZE) self.exit_t_button = SelectorButton( paths.tilePath + "exit-closed-top.png", paths.tilePath + "exit-closed-top.png", origin[0] + padding, origin[1] + padding * 4) self.exit_t_button.resize(self.level.TILE_SIZE, self.level.TILE_SIZE) self.exit_b_button = SelectorButton( paths.tilePath + "exit-closed-bottom.png", paths.tilePath + "exit-closed-bottom.png", origin[0] + padding * 5, origin[1] + padding * 4) self.exit_b_button.resize(self.level.TILE_SIZE, self.level.TILE_SIZE) self.exit_l_button = SelectorButton( paths.tilePath + "exit-closed-left.png", paths.tilePath + "exit-closed-left.png", origin[0] + padding * 10, origin[1] + padding * 4) self.exit_l_button.resize(self.level.TILE_SIZE, self.level.TILE_SIZE) self.exit_r_button = SelectorButton( paths.tilePath + "exit-closed-right.png", paths.tilePath + "exit-closed-right.png", origin[0] + padding * 14, origin[1] + padding * 4) self.exit_r_button.resize(self.level.TILE_SIZE, self.level.TILE_SIZE) self.key_button = SelectorButton(paths.tilePath + "key.png", paths.tilePath + "key.png", origin[0] + padding, origin[1] + padding * 8) self.key_button.resize(self.level.TILE_SIZE, self.level.TILE_SIZE) # Enemy Selectors self.patrol_enemy_button = SelectorButton( paths.tilePath + "enemy-patrol.png", paths.tilePath + "enemy-patrol.png", origin[0] + padding, origin[1] + padding * 13) self.random_enemy_button = SelectorButton( paths.tilePath + "enemy-random.png", paths.tilePath + "enemy-random.png", origin[0] + padding * 5, origin[1] + padding * 13) self.seeker_enemy_button = SelectorButton( paths.tilePath + "enemy-seeker.png", paths.tilePath + "enemy-seeker.png", origin[0] + padding * 9, origin[1] + padding * 13) # Patrol Entry Options (only active if self.patrol_focus is not None) self.patrol_focus_indicator = pygame_gui.Label( [ display.get_width() - self.level.EDITOR_SIZE, origin[1] + padding * 16, self.level.EDITOR_SIZE, self.level.TILE_SIZE ], (60, 60, 60), (60, 60, 60), "Inputting Patrol", constants.FONTS["sizes"]["large"], constants.FONTS["colour"], constants.FONTS["main"]) self.patrol_reset_button = pygame_gui.TextButton( [ display.get_width() - self.level.EDITOR_SIZE, origin[1] + padding * 19, self.level.EDITOR_SIZE / 2, self.level.TILE_SIZE ], (100, 20, 20), (130, 30, 30), "reset", 20, (200, 200, 200), constants.FONTS["main"]) self.patrol_confirm_button = pygame_gui.TextButton( [ display.get_width() - self.level.EDITOR_SIZE / 2, origin[1] + padding * 19, self.level.EDITOR_SIZE / 2, self.level.TILE_SIZE ], (10, 40, 10), (20, 100, 20), "confirm", 20, (200, 200, 200), constants.FONTS["main"]) # Toggle Buttons self.show_keys = True self.show_key_button = pygame_gui.TextButton([ self.level.DISPLAY_SIZE[0], self.level.DISPLAY_SIZE[1] - self.level.TILE_SIZE, self.level.EDITOR_SIZE / 2, self.level.TILE_SIZE ], (40, 40, 40), (60, 60, 60), "toggle keys", 17, (200, 200, 200), constants.FONTS["main"]) self.show_patrols = True self.show_patrols_button = pygame_gui.TextButton( [ self.level.DISPLAY_SIZE[0] + self.level.EDITOR_SIZE / 2, self.level.DISPLAY_SIZE[1] - self.level.TILE_SIZE, self.level.EDITOR_SIZE / 2, self.level.TILE_SIZE ], (40, 40, 40), (60, 60, 60), "toggle patrols", 17, (200, 200, 200), constants.FONTS["main"])