def render(self, console: Console, context: Context) -> None: for entity in self.entities: console.print(entity.x, entity.y, entity.char, fg=entity.color) context.present(console) console.clear()
def render(self, console: tConsole, x: int, y: int, width: int, height: int) -> None: console.print(x, y, f"NAV TARGET: {self._get_nav_target_name()}") text.with_highlighting(console, x, y + 2, "[F]OLLOW") console.print(x + 9, y + 2, self._get_highlighted_name()) text.with_highlighting(console, x, y + 3, "[S]TOP")
def render_main(self, console: Console, player: int, x: int, y: int, width: int, height: int) -> None: if not self.world.has_component(player, Player): return player_position = self.world.component_for_entity(player, Position) mid_x = x + width // 2 mid_y = x + height // 2 for e, (entity_position, entity_renderable, entity_selectable) in self.world.get_components( Position, Renderable, Selectable): diff_x = entity_position.x - player_position.x diff_y = entity_position.y - player_position.y pos_x = mid_x + diff_x pos_y = mid_y + diff_y background_color = colors.BACKGROUND_CLEAR if entity_selectable.selected_main: background_color = colors.BACKGROUND_SELECTED_MAIN if pos_x >= x and pos_y >= y and pos_x <= x + width and pos_y <= y + height: console.print(mid_x + diff_x, mid_y + diff_y, entity_renderable.char, entity_renderable.color, background_color)
def render(self, console: Console) -> None: """ Визуализирует карту. Если плитка в зоне видимости, то она отрисовывается в светлых цветах. Если нет, но она была ранее исследована, тогда отрисовывается темными цветами. Во всех других случаях используется SHROUD (по дефолту) (черные плитки). """ console.tiles_rgb[0:self.width, 0:self.height] = np.select( # np.select позволяет отрисовывать плитки, которые мы хотим, опираясь на то, что указано в condlist condlist=[self.visible, self.explored], choicelist=[self.tiles["light"], self.tiles["dark"]], default=tile_types.SHROUD, ) entities_sorted_for_rendering = sorted( self.entities, key=lambda x: x.render_order.value) for entity in entities_sorted_for_rendering: # печатает только те объекты, которые находятся в FOV if self.visible[entity.x, entity.y]: console.print(x=entity.x, y=entity.y, string=entity.char, fg=entity.color)
def __mockup_render(self, console: tConsole) -> None: values = self.world.component_for_entity(self.player_ship, Destructable) console.print(SCREEN_WIDTH - SIDEBAR_WIDTH + 1, SCREEN_HEIGHT - STATUS_HEIGHT, "CORE", fg=(235, 164, 52)) primitives.bar(console, SCREEN_WIDTH - SIDEBAR_WIDTH + 6, SCREEN_HEIGHT - STATUS_HEIGHT, 28, values.core_percentage, (235, 164, 52)) console.print(SCREEN_WIDTH - SIDEBAR_WIDTH + 1, SCREEN_HEIGHT - STATUS_HEIGHT + 1, "HULL", fg=(168, 168, 168)) primitives.bar(console, SCREEN_WIDTH - SIDEBAR_WIDTH + 6, SCREEN_HEIGHT - STATUS_HEIGHT + 1, 28, values.hull_percentage, (168, 168, 168)) console.print(SCREEN_WIDTH - SIDEBAR_WIDTH + 1, SCREEN_HEIGHT - STATUS_HEIGHT + 2, "SHLD", fg=(109, 182, 214)) primitives.bar(console, SCREEN_WIDTH - SIDEBAR_WIDTH + 6, SCREEN_HEIGHT - STATUS_HEIGHT + 2, 28, values.shield_percentage, (109, 182, 214)) console.print(0, SCREEN_HEIGHT - 1, "[F1] MAIN", fg=colors.TEXT_HIGHLIGHT) console.print(10, SCREEN_HEIGHT - 1, "[F2] COMM") console.print(20, SCREEN_HEIGHT - 1, "[F3] MODS")
def render(self, console: Console) -> None: """ Renders the map. tiles in the 'visible' array are drawn with 'light' colors. nonvisible but explored tiles are drawn with the 'dark colors' otherwise default to SHROUD. """ # console.tiles_rgb[0:self.width, 0:self.height] = self.tiles["dark"] console.tiles_rgb[0:self.width, 0:self.height] = np.select( condlist=[self.visible, self.explored], choicelist=[self.tiles["light"], self.tiles["dark"]], default=tile_types.SHROUD, ) entities_sorted = sorted(self.entities, key=lambda x: x.render_order.value) for entity in entities_sorted: # Only print entities in current Field of View if self.visible[entity.x, entity.y]: console.print(x=entity.x, y=entity.y, string=entity.char, fg=entity.color)
def render(self, console: Console) -> None: ''' Sets tiles and entities to the map. - If the tile is in the "visible" array, draw it with the 'light' color. - If it isn't, but it's been 'explored', draw it with the 'dark' color. - If tile is unexplored, default to "SHROUD". Tiles are sorted into Lists: - 'condlist': Tiles can be both visible AND explored, so they make up a parent list of conditional states. - 'choicelist': Tiles in either of the two color states (sorted depending on FOV calculations). - 'default': Any tiles not in the above lists are effectively unexplored. They will render as 'SHROUD' ''' console.tiles_rgb[0:self.width, 0:self.height] = np.select( # Lists to determine tile appearance condlist=[self.visible, self.explored], choicelist=[self.tiles["light"], self.tiles["dark"]], default=tile_types.SHROUD) # Determine in what order to render entities: entities_sorted_for_rendering = sorted( self.entities, # The Set of entities to sort key=lambda x: x.render_order. value # A custom key for sorting by (using 'render_order' module) ) # Iterate through entities and add one to the console if it exists in a 'visible' area of the map. for entities in entities_sorted_for_rendering: if self.visible[entity.x, entity.y]: console.print(x=entity.x, y=entity.y, string=entity.char, fg=entity.color)
def render_center(self, console: Console, player_pos: Tuple[int, int]) -> None: """Render functions which follows the player. The player will always be at the center, except at the edges of the map. x_pos and y_pos is used to adjust for printing entities on console. args: player_pos = player position on the game map (x, y) """ x, y = player_pos left_render = right_render = top_render = bottom_render = 0 HALF_WIDTH = int(CONSOLE_WIDTH / 2) HALF_HEIGHT = int(CONSOLE_HEIGHT / 2) x_pos = 0 y_pos = 0 if 0 <= x <= HALF_WIDTH: # If the player is at the left-most wall left_render = 0 right_render = CONSOLE_WIDTH elif (self.width - HALF_WIDTH) <= x <= self.width: # If the player is at the right-most wall left_render = self.width - CONSOLE_WIDTH right_render = self.width x_pos = self.width - CONSOLE_WIDTH else: # If the player is in between values above left_render = x - HALF_WIDTH right_render = x + HALF_WIDTH x_pos = x - HALF_WIDTH if 0 <= y <= HALF_HEIGHT: # If the player is at the top wall top_render = 0 bottom_render = CONSOLE_HEIGHT elif (self.height - HALF_HEIGHT) <= y <= self.height: # If the player is at the bottom wall top_render = self.height - CONSOLE_HEIGHT bottom_render = self.height y_pos = self.height - CONSOLE_HEIGHT else: # If the player is in between the values above top_render = y - HALF_HEIGHT bottom_render = y + HALF_HEIGHT y_pos = y - HALF_HEIGHT console.tiles_rgb[0:self.width, 0:self.height] = self.tiles['light'][ left_render:right_render, top_render:bottom_render] entities_sorted = sorted(self.entities, key=lambda _x: _x.render_order.value) for entity in entities_sorted: console.print(x=entity.x - x_pos, y=entity.y - y_pos, string=entity.char, fg=(255, 0, 0))
def bar(console: Console, x: int, y: int, width: int, fill: float, color: Tuple[int, int, int]) -> None: for cx in range(x, x + width): percentage = (cx - x) / width if percentage <= fill: console.print(cx, y, "█", fg=color) else: console.print(cx, y, "▒", fg=color)
def render(self, console: Console, context: Context): self.game_map.render(console) for entity in self.entities: if self.game_map.visible[entity.x, entity.y]: console.print(entity.x, entity.y, entity.char, fg=entity.color) context.present(console) console.clear()
def render(self, console: Console) -> None: console.tiles_rgb[0:self.width, 0:self.height] = np.select( condlist=[self.visible, self.explored], choicelist=[self.tiles["light"], self.tiles["dark"]], default=tile_types.SHROUD ) for entity in self.entities: if self.visible[entity.x, entity.y]: console.print(x= entity.x, y=entity.y, string=entity.char, fg=entity.color)
def render(self, console: Console) -> None: console.tiles_rgb[0:self.width, 0:self.height] = self.tiles['light'] entities_sorted = sorted(self.entities, key=lambda x: x.render_order.value) for entity in entities_sorted: console.print(x=entity.x, y=entity.y, string=entity.char, fg=entity.color)
def render(self, console: Console, context: Context) -> None: self.game_map.render(console) for entity in self.entities: # Only print entities that are in the FOV if self.game_map.visible[entity.x, entity.y]: console.print(entity.x, entity.y, entity.char, fg=entity.color) context.present(console) console.clear()
def render(self, console: Console, context: Context) -> None: """Method for rendering objects in TCOD terminal""" self.g_map.render(console) console.print(x=1, y=47, string=f"HP: {self.player.stats.hp}/{self.player.stats.max_hp}") context.present(console) console.clear()
def render(self, console: Console, viewport_width: int, viewport_height: int) -> None: """ Renders the map If a tile is visible, draw w/ light colors If it isn't but is explored, draw w/ dark colors Otherwise, draw as SHROUD """ self.adjust_viewport_anchor(self.engine.player.x, self.engine.player.y, viewport_width, viewport_height) # bounds of the viewport in map-space, clamped to the map bounds x_start = max(self.viewport_anchor_x, 0) x_end = min(self.viewport_anchor_x + viewport_width, self.width) y_start = max(self.viewport_anchor_y, 0) y_end = min(self.viewport_anchor_y + viewport_height, self.height) # init a new viewport buffer on the assumption that everything's off the map new_tiles = np.full((viewport_width, viewport_height), fill_value=tile_types.EXTERNAL, order="F") # blit the map rectangle onto the new viewport buffer new_tiles[x_start - self.viewport_anchor_x:x_end - self.viewport_anchor_x, y_start - self.viewport_anchor_y:y_end - self.viewport_anchor_y, ] = np.select( condlist=[ self.visible[x_start:x_end, y_start:y_end], self.explored[x_start:x_end, y_start:y_end], ], choicelist=[ self.tiles[x_start:x_end, y_start:y_end]["light"], self.tiles[x_start:x_end, y_start:y_end]["dark"], ], default=tile_types.SHROUD, ) console.tiles_rgb[0:viewport_width, 0:viewport_height] = new_tiles sorted_entities = sorted(self.entities, key=lambda x: x.render_order.value) for entity in sorted_entities: # only draw visible entities in the viewport if (self.visible[entity.x, entity.y] and x_start <= entity.x < x_end and y_start <= entity.y < y_end): console.print( entity.x - self.viewport_anchor_x, entity.y - self.viewport_anchor_y, entity.char, fg=entity.color, )
def render_map(self, console: Console) -> None: # The tiles_rgb function from tcod quickly renders the whole map using the assigned tiles # In other words it takes the widght and height we used when initializing the map. It then renders everything much more # efficiently than the console.print function. console.tiles_rgb[0:self.width, 0:self.height] = self.tiles["dark"] for entity in self.entities: console.print( entity.x, entity.y, entity.charTile, fg=entity.color ) # The print function is not as efficient as tiles_rgb, but can be used to render entities.
def render(self, console: Console, context: Context) -> None: self.game_map.render(console) console.print( x=1, y=47, string=f"HP: {self.player.fighter.hp}/{self.player.fighter.max_hp}", ) context.present(console) console.clear()
def render(self, console: Console, context: Context) -> None: self.game_map.progress_redraw_all_transition() self.game_map.render(console, self.time_of_day) for entity in self.intelligent_entities: if self.game_map.tiles[entity.y][ entity.x].explored or not self.settings["show-fog"]: if entity.name in maps.entity_overview_map: if not self.settings["entity-visibility"][ maps.entity_overview_map[entity.name]]: continue if (isinstance(entity, rbt.Rabbit) and entity.asleep): continue console.print(entity.x, entity.y, entity.char, fg=entity.color, bg=entity.bg_color) if self.selected_entity != None: entity = self.selected_entity if not isinstance(entity, rbt.Burrow) and not isinstance( entity, bb.BerryBush) and not isinstance(entity, cp.Camp): render_selected = True if entity.name in maps.entity_overview_map: render_selected = self.settings["entity-visibility"][ maps.entity_overview_map[entity.name]] if render_selected: console.print(entity.x, entity.y, entity.char, fg=entity.color, bg=entity.bg_color) if self.settings["show-ui"]: self.stats_panel.render(console) self.hover_panel.render(console) self.selection_panel.render(console) self.action_log_panel.render(console) self.game_menu_panel.render(console) self.controls_panel.render(console) if self.settings["show-entity-overview"]: self.entity_overview_panel.render(console) context.present(console)
def render(self, console: Console, context: Context) -> None: ''' GameMap instance renders independently using its own .render() method. Then 'tcod.context' displays the console to the screen. ''' self.game_map.render(console) console.print( x=1, y=47, string= f"HP: {self.player.fighter.hp} / {self.player.fighter.max_hp}") context.present(console) console.clear()
def render(self, console: Console, use_fov: bool = True) -> None: """Render everything visible or memorized to the console.""" if use_fov: console.tiles_rgb[0:self.width, 0:self.height] = np.select( [self.visible, self.explored], [self.tiles["light"], self.tiles["dark"]], default=tile_types.FOG, ) else: console.tiles_rgb[0:self.width, 0:self.height] = self.tiles["light"] for e in self.entities: # Only show entities in the player's field of view if not use_fov or self.visible[e.x, e.y]: console.print(e.x, e.y, e.char, fg=e.color)
def render(self, console: Console) -> None: console.tiles_rgb[0:self.width, 0:self.height] = np.select( condlist=[self.visible, self.explored], choicelist=[self.tiles["color_light"], self.tiles["color_dark"]], default=tile_type.fog_of_war, ) entities_sorted = sorted(self.entities, key=lambda x: x.r_order.value) for entity in entities_sorted: if self.visible[entity.x, entity.y]: console.print(x=entity.x, y=entity.y, string=entity.char, fg=entity.color)
def render(self, console: Console) -> None: """ Renders map. If tile in "visible" array, draw with "light" colors, otherwise, if it is "explored" array, draw with "dark" colors, otherwise, default is "SHROUD". """ console.tiles_rgb[0:self.width, 0:self.height] = np.select( condlist=[self.visible, self.explored], choicelist=[self.tiles["light"], self.tiles["dark"]], default=tile_types.SHROUD) for entity in self.entities: #Only print entities in FOV if self.visible[entity.x, entity.y]: console.print(entity.x, entity.y, entity.char, fg=entity.color)
def __render_entity_list(self, console: Console, x: int, y: int, width: int, height: int) -> None: line = 0 self.entity_list = [] for entity, (entity_renderable, entity_name, entity_selectable) in self.world.get_components( Renderable, Name, Selectable): self.entity_list.append(entity) if entity_selectable.selected_main: console.print(x + 1, y + line, "►", colors.TEXT_DEFAULT) first = False name = entity_name.formatted_name console.print(x + 3, y + line, name, entity_renderable.color) line = line + 1 if line > height: break
def with_highlighting( console: Console, x: int, y: int, text: str, text_color: Tuple[int, int, int] = TEXT_DEFAULT, highlight_color: Tuple[int, int, int] = TEXT_HIGHLIGHT) -> None: dx = x color = text_color for char in text: if char is "[": color = highlight_color console.print(dx, y, char, color) if char is "]": color = text_color dx = dx + 1
def render(self, console: Console) -> None: console.tiles_rgb[0:self.width, 0:self.height] = np.select( condlist=[self.visible, self.explored], choicelist=[self.tiles["light"], self.tiles["dark"]], default=tile_types.SHROUD, ) entities_sorted_for_rendering = sorted( self.entities, key=lambda x: x.render_order.value) for entity in entities_sorted_for_rendering: # Only print entities that are in FOV if self.visible[entity.x, entity.y]: console.print(x=entity.x, y=entity.y, string=entity.char, fg=entity.color)
def render(self, console: Console) -> None: """ Renders the map. If a tile is in the "visible" array, then draw it with the "light" colors. If it isn't, but it's in the "explored" array, then draw it with the "dark" colors. Otherwise, the default is "SHROUD". """ console.tiles_rgb[0:self.width, 0:self.height] = np.select( condlist=[self.visible, self.explored], choicelist=[self.tiles["light"], self.tiles["dark"]], default=tile_types.SHROUD ) for entity in self.entities: # Only print entities that are in the FOV. if self.visible[entity.x, entity.y]: console.print(entity.x, entity.y, entity.char, fg=entity.color)
def render(self, console: Console, context: Context) -> None: """ The display portion of the game loop, now as its own method. :param console: :param context: :return: None """ # draw the game map on screen self.game_map.render(console) # loop through all the entities for entity in self.entities: # and place them on the console console.print(entity.x, entity.y, entity.char, entity.color) # update the screen so we can see them context.present(console) # clear console to prevent 'trailing' console.clear()
def render(self, console: Console) -> None: """ Renders the map. If a tile is in the "visible" array, then draw it with the "light" colors. If it isn't, but it's in the "explored" array, then draw it with the "dark" colors. Otherwise, the default is "SHROUD". """ console.tiles_rgb[0:self.width, 0:self.height] = np.select( condlist=[self.visible, self.explored], choicelist=[self.tiles["light"], self.tiles["dark"]], default=tile_types.SHROUD ) entities_sorted_for_rendering = sorted(self.entities, key=lambda x: x.render_order.value) for entity in entities_sorted_for_rendering: if self.visible[entity.x, entity.y]: console.print(x=entity.x, y=entity.y, string=entity.char, fg=entity.color)
def render(self, console: Console) -> None: """ Renders the map If tile is in "visible", draw with "light" If it isn't but it's in "explored", draw with "dark" Otherwise "SHROUD" """ console.tiles_rgb[0:self.width, 0:self.height] = np.select( condlist=[self.visible, self.explored], choicelist=[self.tiles["light"], self.tiles["dark"]], default=tile_types.SHROUD, ) for entity in self.entities: # only print entities in FOV if self.visible[entity.x, entity.y]: console.print(entity.x, entity.y, entity.char, fg=entity.color)
def render(self, console: Console) -> None: """ Renders the map. If a tile is in the "visible" array, then draw it with the "light" colors. If it isn't, but it's in the "explored" array, then draw it with the "dark" colors. Otherwise, the default is "SHROUD". """ console.tiles_rgb[:] = np.select( condlist=[self.fov, self.explored], choicelist=[self.tiles["light"], self.tiles["dark"]], default=SHROUD) if not CONFIG.get('debug'): where_fov = np.where(self.fov[:]) else: where_fov = np.where(self.tiles[:]) self.render_debug(console) always_visible = self.entities.find_all_visible() for entity in always_visible: if self.explored[entity.x, entity.y]: console.print(entity.x, entity.y, entity.display_char, fg=entity.display_color) for idx, x in enumerate(where_fov[0]): y = where_fov[1][idx] current_entities = self.entities.get_entities_in_position((x, y)) entities_in_render_order = sorted( current_entities, key=lambda x: x.render_order.value, reverse=True) for entity in entities_in_render_order: if not entity.invisible: console.print(entity.x, entity.y, entity.display_char, fg=entity.display_color) break entities_in_render_order.clear() entity = None