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, 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()
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 draw_patrol(self, display, enemy): patrol = enemy["patrol"] pause_text = pygame_gui.Text("", constants.FONTS["sizes"]["medium"], constants.FONTS["colour"], constants.FONTS["main"], 0, 0) previous_position = patrol[0] # set to spawn for step in patrol[1:] + [patrol[0]]: # spawn moved to end (as draw path from current to last position) if type(step) not in [int, float]: # Draw point on patrol position (of previous_position) pos = [round(previous_position[0] * self.level.TILE_SIZE + self.level.TILE_SIZE/2), round(previous_position[1]*self.level.TILE_SIZE + self.level.TILE_SIZE/2)] pygame.draw.circle(display, (255, 255, 255), pos, round(self.level.TILE_SIZE/6)) # Draw path from current to previous path = search.GridPath(self.level.format, step, previous_position, constants.WALL_FORMATS).get_path() if path is not None: # as could be blocked if user adds a wall self.draw_path(display, [step] + path) # adding step to front so draws from previous_position previous_position = step.copy() # otherwise will change to match step (mutable) else: pause_text.change_text(str(step)) x = previous_position[0] * self.level.TILE_SIZE + 5 y = previous_position[1] * self.level.TILE_SIZE pause_text.change_position(x, y) pause_text.draw(display)
def __init__(self, display): self.display = display self.state = "load_game" self.game_reference = None # Background Setup self.background = pygame_gui.Image( paths.imagePath + "background-load.png", 0, 0) # 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 Level: ", constants.FONTS["sizes"]["large"], constants.FONTS["colour"], constants.FONTS["main"], 275, 55) self.file_selector = FileSelector(self, [275, 100]) 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.page_back_button = pygame_gui.Button( paths.uiPath + "pageback.png", paths.uiPath + "pageback-hover.png", 670, 53) self.page_forward_button = pygame_gui.Button( paths.uiPath + "pageforward.png", paths.uiPath + "pageforward-hover.png", 710, 53) self.run()
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()
def __init__(self, text, href, x, y): self.href = href self.text = pygame_gui.Text( text, constants.FONTS["sizes"]["medium"], constants.FONTS["colour"], constants.FONTS["main"], x, y) self.rect = self.text.get_rect() self.hover_text = pygame_gui.Text( text, constants.FONTS["sizes"]["medium"], constants.FONTS["colour"], constants.FONTS["main"], x, y) self.hover_text.graphic_font.set_underline(True) self.hover_text.change_text(self.hover_text.text) # acts as update, font must be re-rendered to show underline.
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)
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, model, GUI): self.display = display self.model = model self.GUI = GUI # Background self.stars = background.Starscape(self.display.get_rect()) # General Setup (surface + camera) self.game_surface = surface.Surface(constants.GAME_RECT) self.game_surface.main_surface.set_colorkey(constants.COLOURS["black"]) # so stars drawn to display first are seen # Map Setup self.world = VisualWorld(self.model) # Focuses self.tile_focus = None # record of the current tile clicked self.active_unit = None # record of current unit clicked on # Units Image Setup self.unit_images = { "base-unit": pygame.image.load(paths.unitPath + "base-unit.png").convert_alpha(), "unit-counter": pygame.image.load(paths.unitPath + "unit-counter.png").convert_alpha(), "blue-scout": pygame.image.load(paths.unitPath + "blue-scout.png").convert_alpha(), "blue-swordsman": pygame.image.load(paths.unitPath + "blue-swordsman.png").convert_alpha(), "blue-archer": pygame.image.load(paths.unitPath + "blue-archer.png").convert_alpha(), "blue-horseman": pygame.image.load(paths.unitPath + "blue-horseman.png").convert_alpha(), "blue-catapult": pygame.image.load(paths.unitPath + "blue-catapult.png").convert_alpha(), "yellow-scout": pygame.image.load(paths.unitPath + "yellow-scout.png").convert_alpha(), "yellow-swordsman": pygame.image.load(paths.unitPath + "yellow-swordsman.png").convert_alpha(), "yellow-archer": pygame.image.load(paths.unitPath + "yellow-archer.png").convert_alpha(), "yellow-horseman": pygame.image.load(paths.unitPath + "yellow-horseman.png").convert_alpha(), "yellow-catapult": pygame.image.load(paths.unitPath + "yellow-catapult.png").convert_alpha(), "green-scout": pygame.image.load(paths.unitPath + "green-scout.png").convert_alpha(), "green-swordsman": pygame.image.load(paths.unitPath + "green-swordsman.png").convert_alpha(), "green-archer": pygame.image.load(paths.unitPath + "green-archer.png").convert_alpha(), "green-horseman": pygame.image.load(paths.unitPath + "green-horseman.png").convert_alpha(), "green-catapult": pygame.image.load(paths.unitPath + "green-catapult.png").convert_alpha(), "red-scout": pygame.image.load(paths.unitPath + "red-scout.png").convert_alpha(), "red-swordsman": pygame.image.load(paths.unitPath + "red-swordsman.png").convert_alpha(), "red-archer": pygame.image.load(paths.unitPath + "red-archer.png").convert_alpha(), "red-horseman": pygame.image.load(paths.unitPath + "red-horseman.png").convert_alpha(), "red-catapult": pygame.image.load(paths.unitPath + "red-catapult.png").convert_alpha(), } self.unit_action_images = { "move": pygame.image.load(paths.unitPath + "move-indicator.png"), "attack": pygame.image.load(paths.unitPath + "attack-indicator.png"), "conquer": pygame.image.load(paths.unitPath + "conquer-indicator.png"), } self.unit_health_text = pygame_gui.Text("", 13, constants.FONTS["colour"], constants.FONTS["main"], 0, 0) # changed during unit drawing
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)
def __init__(self, model): self.model = model model_tiles = self.model.world.tiles self.tiles = [] self.settlement_names = [] for row in model_tiles: self.tiles.append([]) for tile in row: if tile.get_type() == "c": new_tile = VisualCityTile(tile) # Create City Text settlement_text = pygame_gui.Text(new_tile.city_link.get_name(), constants.FONTS["sizes"]["small"], (255, 255, 255), constants.FONTS["main"], new_tile.x, new_tile.y + constants.TILE_HEIGHT + get_tile_offset("c")) settlement_text.x += (constants.TILE_WIDTH / 2) - settlement_text.get_rect()[2] / 2 self.settlement_names.append(settlement_text) else: new_tile = VisualTile(tile) self.tiles[len(self.tiles) - 1].append(new_tile)
def __init__(self, x, y): self.x = x self.y = y self.path = paths.mapPath self.maps = [ filename.replace(".csv", "") for filename in os.listdir(self.path) ] # all files are .csv self.back_button = pygame_gui.Button( paths.uiPath + "pageback.png", paths.uiPath + "pageback-hover.png", self.x, self.y) self.map_text = pygame_gui.Text("", constants.FONTS["sizes"]["medium"], constants.FONTS["colour"], constants.FONTS["main"], self.x + 40, self.y + 5) self.forward_button = pygame_gui.Button( paths.uiPath + "pageforward.png", paths.uiPath + "pageforward-hover.png", self.x + 230, self.y) self.map_number = 0 # index of self.maps, the current selection. self.update()
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, 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)
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()